Mecha.Core
2.1.46
See the version list below for details.
dotnet add package Mecha.Core --version 2.1.46
NuGet\Install-Package Mecha.Core -Version 2.1.46
<PackageReference Include="Mecha.Core" Version="2.1.46" />
paket add Mecha.Core --version 2.1.46
#r "nuget: Mecha.Core, 2.1.46"
// Install Mecha.Core as a Cake Addin #addin nuget:?package=Mecha.Core&version=2.1.46 // Install Mecha.Core as a Cake Tool #tool nuget:?package=Mecha.Core&version=2.1.46
I try to make idiot proof software but the world keeps making better idiots.
Or at least that's how it seems to us much of the time. You post a new application feature and the user's find a way to break it. In reality it's because we didn't think of an edge case that they found. I mean who can possibly think up all of these possibilities? A cracked out squirrel? Perhaps a raccoon with ADHD? Neither really work out in the long run as eventually they rise up against society to overthrow it. They're trained with computers at that point so there is no stopping them. And personally I'm too lazy to do this myself so I guess that leaves writing some code to do it, but thankfully I've already done that for you.
Mecha is a library to automatically test classes with the ultimate goal being to find ways to break the code. It can help with unit testing, security testing via data fuzzing, testing for concurrency issues, and check for fault tolerance. With one line of code, you can test every method in a class automatically. Best part is it ties into the testing framework that you're already using.
The Code and What It's Doing
Mech.BreakAsync<MyClass>();
Seriously, that's it. With that Mecha searches for any public methods and properties, loops through them, finds interesting inputs for the methods, and runs them looking for exceptions to be thrown. Once an exception is thrown, it then uses the input to find the smallest possible value that still results in an issue. It then saves these issues as test cases for the future.
Ok, so it breaks my method and does what? Mecha uses a concept borrowed from property testing known as shrinking. For instance you generate a list of 100 items for the method and it breaks. Mecha then removes some of the values and sees if it continues to break. It then continues to do this until it finds a list as small as possible that still breaks.
Supported Types and Object Generation
Mostly everything. It will generate inputs for all value types, enums, and even complete classes. It will give your methods FileStreams, HttpClients, Streams, etc. that throw exceptions themselves to see if your code can handle edge cases. Stubs/substitutes are automatically generated and fed through depending on the parameters of your method. It checks bounds, null, etc. as well. On top of that it takes into account any ValidationAttributes that it finds. So if you specify a range for a parameter, it will keep the values inside that range.
Non Ninja Mutants
On a successful run where no exception is thrown the input values are potentially mutated in ways that are known to cause issues. For instance adding \0 in the middle of a string, etc. These are then run through the system to see if they can break the code. If they do, they're added to the set of results. If not, we mutate again and rerun up until the max number of mutations that you set in the options.
Shrinking All the Things
On a run where an exception is thrown, the input values are "shrunk". This involves taking a value and making it smaller in some way. For instance if a list of 100 values throws an exception, the system will remove 20 of them and try again. If it throws an exception, we shrink it again and again until it passes or we hit the max number of shrinks set in the options.
Getting Started
All you need to do is install the framework specific library from NuGet:
Framework | Library |
---|---|
xUnit.Net | Mecha.xUnit |
All other frameworks | Mecha.Core |
This list should grow as new supported frameworks are added. If your library isn't supported, you can get access to the Mech class itself by adding the Mecha.Core library to your project. And if you like the library and would like to support your framework of choice, we'll gladly accept pull requests to add it. Anyway, what does the framework specific libraries give you?
xUnit.Net
[Property]
public void MyTest(int value1,int value2, ...)
{
...
}
The above code adds the Property attribute which lets xUnit.Net know that you want to assign values for value1, value2, etc. using the library. It then aggregates all of the failed tests in one result in the Test Explorer window with details about what values broke the test.
Everything Else
Mech.BreakAsync<MyClass>();
There are variations of the above method depending on your needs. Also note that you can specify various options including how long it should attempt to generate values, the number of shrinks to attempt, and the number of test cases to run from the generated values.
FAQ
What if I have a method that I don't want the library to run?
- The library comes with a DoNotBreak Attribute. Any method marked with this will be skipped by the library.
Where is it saving the failed runs for later?
- By default the system places the failed runs in a directory called Mecha under the test library's bin directory. It's possible to override this and store the information somewhere else by implementing the Mecha.Core.Datasources.Interfaces.IDatasource interface.
Can I create my own data generators?
- Yes by implementing the Mecha.Core.Generator.Interfaces.IGenerator interface. The system should automatically pick them up and use them.
Can I create my own data shrinker?
- Yes by implementing the Mecha.Core.Shrinker.Interfaces.IShrinker interface. The system should automatically pick them up and use them.
Can I create my own data mutator?
- Yes by implementing the Mecha.Core.Mutator.Interfaces.IMutator interface. The system should automatically pick them up and use them.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- FileCurator (>= 4.0.71)
- Mirage (>= 4.0.87)
- NSubstitute (>= 5.1.0)
- System.Text.Json (>= 8.0.3)
-
net8.0
- FileCurator (>= 4.0.71)
- Mirage (>= 4.0.87)
- NSubstitute (>= 5.1.0)
- System.Text.Json (>= 8.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Mecha.Core:
Package | Downloads |
---|---|
Mecha.xUnit
Mecha is a C# library that enables automatic testing of classes with the goal of finding ways to break the code. It provides various testing capabilities such as unit testing, security testing through data fuzzing, checking for concurrency issues, and verifying fault tolerance. With just a single line of code, Mecha can automatically test every method in a class. The library seamlessly integrates with your existing testing framework. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.121 | 37 | 11/4/2024 |
2.1.120 | 283 | 10/30/2024 |
2.1.119 | 197 | 10/29/2024 |
2.1.118 | 179 | 10/29/2024 |
2.1.117 | 1,109 | 10/10/2024 |
2.1.116 | 269 | 10/9/2024 |
2.1.115 | 217 | 10/8/2024 |
2.1.114 | 425 | 10/1/2024 |
2.1.113 | 233 | 9/30/2024 |
2.1.112 | 357 | 9/27/2024 |
2.1.111 | 347 | 9/24/2024 |
2.1.110 | 252 | 9/23/2024 |
2.1.109 | 422 | 9/17/2024 |
2.1.108 | 464 | 9/9/2024 |
2.1.107 | 300 | 9/6/2024 |
2.1.106 | 414 | 9/2/2024 |
2.1.105 | 293 | 8/29/2024 |
2.1.104 | 302 | 8/27/2024 |
2.1.103 | 228 | 8/26/2024 |
2.1.102 | 348 | 8/23/2024 |
2.1.101 | 278 | 8/22/2024 |
2.1.100 | 323 | 8/21/2024 |
2.1.99 | 577 | 8/20/2024 |
2.1.98 | 268 | 8/19/2024 |
2.1.97 | 356 | 8/15/2024 |
2.1.96 | 262 | 8/14/2024 |
2.1.95 | 284 | 8/13/2024 |
2.1.94 | 360 | 8/5/2024 |
2.1.93 | 158 | 8/2/2024 |
2.1.92 | 152 | 8/1/2024 |
2.1.91 | 235 | 7/31/2024 |
2.1.90 | 452 | 7/25/2024 |
2.1.89 | 584 | 7/11/2024 |
2.1.88 | 207 | 7/10/2024 |
2.1.87 | 195 | 7/10/2024 |
2.1.86 | 610 | 7/1/2024 |
2.1.85 | 347 | 6/27/2024 |
2.1.84 | 224 | 6/26/2024 |
2.1.83 | 294 | 6/25/2024 |
2.1.82 | 274 | 6/22/2024 |
2.1.81 | 184 | 6/21/2024 |
2.1.80 | 188 | 6/21/2024 |
2.1.79 | 247 | 6/19/2024 |
2.1.78 | 270 | 6/18/2024 |
2.1.77 | 254 | 6/17/2024 |
2.1.76 | 284 | 6/14/2024 |
2.1.75 | 253 | 6/13/2024 |
2.1.74 | 266 | 6/12/2024 |
2.1.73 | 615 | 5/31/2024 |
2.1.72 | 257 | 5/30/2024 |
2.1.71 | 252 | 5/29/2024 |
2.1.70 | 307 | 5/27/2024 |
2.1.69 | 547 | 5/20/2024 |
2.1.68 | 249 | 5/17/2024 |
2.1.67 | 249 | 5/16/2024 |
2.1.66 | 258 | 5/15/2024 |
2.1.65 | 256 | 5/13/2024 |
2.1.64 | 300 | 5/8/2024 |
2.1.63 | 264 | 5/7/2024 |
2.1.62 | 296 | 5/6/2024 |
2.1.61 | 388 | 5/3/2024 |
2.1.60 | 161 | 5/2/2024 |
2.1.59 | 167 | 5/1/2024 |
2.1.58 | 229 | 4/30/2024 |
2.1.57 | 345 | 4/29/2024 |
2.1.56 | 645 | 4/15/2024 |
2.1.55 | 270 | 4/12/2024 |
2.1.54 | 256 | 4/11/2024 |
2.1.53 | 261 | 4/10/2024 |
2.1.52 | 360 | 4/2/2024 |
2.1.51 | 242 | 4/1/2024 |
2.1.50 | 278 | 3/29/2024 |
2.1.49 | 390 | 3/28/2024 |
2.1.48 | 515 | 3/19/2024 |
2.1.47 | 213 | 3/18/2024 |
2.1.46 | 213 | 3/15/2024 |
2.1.45 | 238 | 3/14/2024 |
2.1.44 | 279 | 3/13/2024 |
2.1.43 | 280 | 3/12/2024 |
2.1.42 | 238 | 3/11/2024 |
2.1.41 | 229 | 3/8/2024 |
2.1.40 | 268 | 3/7/2024 |
2.1.39 | 267 | 3/6/2024 |
2.1.38 | 266 | 3/5/2024 |
2.1.37 | 470 | 3/4/2024 |
2.1.36 | 319 | 3/1/2024 |
2.1.35 | 242 | 2/29/2024 |
2.1.34 | 234 | 2/28/2024 |
2.1.33 | 242 | 2/27/2024 |
2.1.32 | 182 | 2/27/2024 |
2.1.31 | 276 | 2/23/2024 |
2.1.30 | 112 | 2/23/2024 |
2.1.29 | 274 | 2/22/2024 |
2.1.28 | 271 | 2/21/2024 |
2.1.27 | 273 | 2/20/2024 |
2.1.26 | 217 | 2/19/2024 |
2.1.25 | 121 | 2/16/2024 |
2.1.24 | 227 | 2/15/2024 |
2.1.23 | 396 | 2/14/2024 |
2.1.22 | 244 | 2/13/2024 |
2.1.21 | 224 | 2/12/2024 |
2.1.20 | 222 | 2/9/2024 |
2.1.19 | 250 | 2/8/2024 |
2.1.18 | 232 | 2/7/2024 |
2.1.17 | 135 | 2/6/2024 |
2.1.16 | 288 | 2/5/2024 |
2.1.15 | 304 | 2/1/2024 |
2.1.14 | 993 | 1/31/2024 |
2.1.13 | 198 | 1/30/2024 |
2.1.12 | 261 | 1/29/2024 |
2.1.11 | 263 | 1/26/2024 |
2.1.10 | 253 | 1/25/2024 |
2.1.9 | 194 | 1/24/2024 |
2.1.8 | 229 | 1/23/2024 |
2.1.7 | 183 | 1/22/2024 |
2.1.6 | 291 | 1/16/2024 |
2.1.5 | 220 | 1/12/2024 |
2.1.4 | 239 | 1/11/2024 |
2.1.3 | 244 | 1/10/2024 |
2.1.2 | 262 | 1/9/2024 |
2.1.1 | 239 | 1/7/2024 |
2.1.0 | 610 | 12/28/2023 |
2.0.74 | 200 | 12/27/2023 |
2.0.73 | 408 | 12/21/2023 |
2.0.72 | 252 | 12/20/2023 |
2.0.71 | 248 | 12/19/2023 |
2.0.70 | 237 | 12/18/2023 |
2.0.69 | 241 | 12/15/2023 |
2.0.68 | 265 | 12/14/2023 |
2.0.67 | 332 | 12/13/2023 |
2.0.66 | 903 | 12/5/2023 |
2.0.65 | 289 | 11/24/2023 |
2.0.64 | 246 | 11/23/2023 |
2.0.63 | 207 | 11/22/2023 |
2.0.62 | 221 | 11/21/2023 |
2.0.61 | 208 | 11/20/2023 |
2.0.60 | 495 | 11/17/2023 |
2.0.59 | 244 | 11/16/2023 |
2.0.58 | 291 | 11/15/2023 |
2.0.57 | 213 | 11/13/2023 |
2.0.56 | 216 | 11/9/2023 |
2.0.55 | 205 | 11/8/2023 |
2.0.54 | 206 | 11/7/2023 |
2.0.53 | 250 | 11/6/2023 |
2.0.52 | 277 | 11/3/2023 |
2.0.51 | 309 | 11/1/2023 |
2.0.50 | 228 | 10/31/2023 |
2.0.49 | 254 | 10/30/2023 |
2.0.48 | 251 | 10/27/2023 |
2.0.47 | 260 | 10/26/2023 |
2.0.46 | 242 | 10/25/2023 |
2.0.45 | 271 | 10/17/2023 |
2.0.44 | 272 | 10/13/2023 |
2.0.43 | 263 | 10/11/2023 |
2.0.42 | 347 | 10/4/2023 |
2.0.41 | 257 | 9/26/2023 |
2.0.40 | 234 | 9/25/2023 |
2.0.39 | 268 | 9/21/2023 |
2.0.38 | 235 | 9/20/2023 |
2.0.37 | 240 | 9/19/2023 |
2.0.36 | 232 | 9/18/2023 |
2.0.35 | 294 | 9/15/2023 |
2.0.34 | 244 | 9/14/2023 |
2.0.33 | 257 | 9/13/2023 |
2.0.32 | 282 | 9/12/2023 |
2.0.31 | 273 | 9/11/2023 |
2.0.30 | 362 | 9/8/2023 |
2.0.29 | 277 | 9/7/2023 |
2.0.28 | 255 | 9/6/2023 |
2.0.27 | 269 | 9/5/2023 |
2.0.26 | 316 | 9/4/2023 |
2.0.25 | 366 | 9/1/2023 |
2.0.24 | 280 | 8/31/2023 |
2.0.23 | 299 | 8/30/2023 |
2.0.22 | 315 | 8/29/2023 |
2.0.21 | 339 | 8/28/2023 |
2.0.20 | 331 | 8/25/2023 |
2.0.19 | 280 | 8/24/2023 |
2.0.18 | 262 | 8/23/2023 |
2.0.17 | 285 | 8/22/2023 |
2.0.16 | 330 | 8/18/2023 |
2.0.15 | 267 | 8/17/2023 |
2.0.14 | 295 | 8/16/2023 |
2.0.13 | 1,401 | 8/10/2023 |
2.0.12 | 273 | 8/9/2023 |
2.0.11 | 341 | 8/8/2023 |
2.0.10 | 211 | 8/7/2023 |
2.0.9 | 213 | 8/3/2023 |
2.0.8 | 201 | 8/2/2023 |
2.0.7 | 233 | 7/27/2023 |
2.0.6 | 188 | 7/26/2023 |
2.0.5 | 216 | 7/25/2023 |
2.0.4 | 236 | 7/20/2023 |
2.0.3 | 184 | 7/19/2023 |
2.0.2 | 225 | 7/17/2023 |
2.0.1 | 1,758 | 12/28/2022 |
2.0.0 | 485 | 12/12/2022 |
1.0.41 | 531 | 12/9/2022 |
1.0.40 | 863 | 6/10/2022 |
1.0.38 | 1,006 | 4/12/2022 |
1.0.37 | 805 | 1/11/2022 |
1.0.35 | 692 | 9/14/2021 |
1.0.34 | 563 | 8/24/2021 |
1.0.33 | 648 | 7/26/2021 |
1.0.32 | 729 | 6/1/2021 |
1.0.30 | 608 | 5/20/2021 |
1.0.26 | 548 | 5/20/2021 |
1.0.25 | 566 | 5/20/2021 |
1.0.24 | 533 | 5/20/2021 |
1.0.22 | 552 | 5/19/2021 |
1.0.21 | 533 | 5/19/2021 |
1.0.20 | 530 | 5/18/2021 |
1.0.17 | 525 | 5/18/2021 |
1.0.16 | 538 | 5/3/2021 |
1.0.15 | 561 | 4/30/2021 |
1.0.14 | 550 | 4/29/2021 |
1.0.10 | 537 | 4/26/2021 |
1.0.9 | 541 | 4/26/2021 |
1.0.8 | 542 | 4/26/2021 |
1.0.7 | 554 | 4/26/2021 |
1.0.6 | 606 | 4/24/2021 |
1.0.5 | 534 | 4/24/2021 |