Skip to main content

Setting Test Cases

Programmatic testcase declaration

In addition to passing testcases as command-line arguments or letting the SDK fetch and reuse the set of test cases already submitted to the baseline version, sometimes you may want to specify your test cases as code or infer them during the test runtime, based on the set of local files or datasets in a given directory, or rows of a given column in a CSV file, or a nested array of JSON response of a particular API endpoint, etc.

In Python, you could use the testcases parameter of the @touca.workflow decorator which accepts either a list, a generator, or a generator function.

@touca.workflow(testcases=["alice", "bob", "charlie"])
def students_test(username: str):
student = code_under_test.find_student(username)
touca.check("gpa", student.gpa)

Here's the same snippet if we were to use a generator function.

def find_testcases():
for username in ['alice', 'bob', 'charlie']:
yield username

@touca.workflow(testcases=find_testcases)
def students_test(username: str):
student = code_under_test.find_student(username)
touca.check("gpa", student.gpa)