Creating your project
Step 0: Create your project
You begin by writing your class in C# withSystem.Console.WriteLine debugging. cd to a directory where you would like to create your C# project. Use the dotnet CLI to create a new console project as shown below. A directory will be created for the new project.
MyTimes10App/Program.cs with the following content:
Using our SDK classes
Recall that the basic SDK workflow is:- Add a PackageReference to
Antithesis.SDKin your .NET project file. - Call SDK methods from your code.
- Build your .NET project.
- Deploy your build.
Step 1: Add a PackageReference to Antithesis.SDK in your .NET project file
The Antithesis.SDK package is available on NuGet:
Step 2. Call SDK methods from your code
You wrote a method to multiply numbers by ten. What sorts of properties should it have? The output should always be even. You should also make sure you are testing a wide variety of inputs, such as both even and odd numbers. Modify the code. The modifications are individually explained below.-
Lines 1-2 You imported the Antithesis .NET SDK and support for
System.Text.Json.Nodes.JsonObject. -
You added two assertions to Times10.
- Line 13 You assert that the result is even using an Always Assertion. This is a fairly conventional assertion.
- Line 8 You insert a Sometimes Assertion, or an assertion that something will happen at least once across the entire testing session. You assert that sometimes during testing, the method will be called with an odd argument. The two types of assertions complement one another: Always Assertions assert that the behavior is correct, whereas Sometimes Assertions assert that you are testing under wide enough conditions to surface any potential incorrect behavior. In this case, the output would trivially be even if you only passed it even inputs — you must ensure your properties are not being trivially satisfied!
- Lines 20-24 You use randomness to call the method with many random values (between 0 and 499). Previously, you called the method with hardcoded values but now you will pass the method values and test that the output is always even. This approach is more powerful but makes Sometimes Assertions necessary — now you must test that you are passing the method odd values, whereas previously the tests were hardcoded so you were certain that you were passing it odd values.
-
You call the method
Nextto draw a random integer, and then pass this random integer toTimes10. You use a loop to do this fifty times in a row. Every time theTimes10method is called in this loop, it triggers the assertions in lines 8 & 13. -
In summary: You’ll test
Times10by passing it a random integer fifty times in a row. You’ve asserted that all fifty outputs must be even and that at least one random integer must be odd.
Preparing your project for Antithesis
To send code to Antithesis, you should build as described above. Antithesis will explore your software and search for violations of the properties you have defined. You must send us containers as described in getting started. The executable should be included in your container.This example is simplified compared to what the full quickstart guide describes. Note
that the C# top level statements are the workload and the
Times10 method is the software itself.
There are no dependencies.