Creating your project
Step 0: Write your project. You begin by writing your function in Python with print debugging. Make a directory where you would like to create your Python project andcd to that directory. (Our directory is /home/me/Projects — this will be printed in the logs later.)
myapp.py with the following content:
Using our SDK functions
Recall that the basic SDK workflow is:- Use SDK functions in your code.
- Run your Python project.
Step 1: Include the Antithesis SDK in dependencies
Step 2: Use Antithesis SDK functions in your code
You wrote a function 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. Here’s how you’d do this with our SDK assertions:- Lines 1-2 You import the assert and random libraries.
-
You add two assertions to times10.
- Line 7 You assert that the result is always even using an always assertion.
- Line 5 You insert a Sometimes Assertion, stating that something will happen at least once across the entire testing session; in this case, that the function will be called with an odd argument. The two assertions complement one another: Always Assertions assert that the behavior is correct, while Sometimes Assertions assert that you’re testing under wide enough conditions to surface any potential incorrect behavior, to ensure the desired properties are not being trivially satisfied.
-
Lines 12-14 You use randomness to call the function with many random values (between 0 and 500). Previously, you called the function with hard-coded values but now you’ll pass the function random 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’re passing the function odd values, whereas previously the tests were hard-coded so you were certain that you were passing it odd values.
You call the random package’s GetRandom function to draw a random number, and then pass this random number to
times10. You use a loop to do this 50 times in a row. Every time the times10 function is called in this loop, it triggers the assertions in lines 12 & 14. -
In summary You’ll test
times10by passing it a random integer 50 times in a row. You have asserted that all 50 outputs must be even and that at least one random input must be odd.
Step 3: Deploy your project
If you’re planning for local deployment then you’d be done here, but suppose instead you intend to send your project to Antithesis for testing. 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.This example is simplified compared to what the full quickstart guide describes. Note that the function
main is the workload and times10 is the software itself. There are no other dependencies.