Parameterized testing
Consider the following Vector
class:
A set of tests could look as follows:
Testing multiple vector sizes and element types in a single test suite would make it far more effective. This can be easily achieved by parameterizing the test suite described above. There are several approaches to accomplish this. One method is to parameterize only the testset blocks within a testenv
:
which prints out the following test results
Test Environment: Vector implementationtestset: fill(N=2,T=int32)3/3 tests passedtestset: fill(N=3,T=int32)4/4 tests passedtestset: fill(N=2,T=int64)3/3 tests passedtestset: fill(N=3,T=int64)4/4 tests passed
Alternatively, we can parameterize the testenv
:
which prints out the results as follows:
Test Environment: Vector implementation(N=2,T=int32)testset: fill3/3 tests passedTest Environment: Vector implementation(N=3,T=int32)testset: fill4/4 tests passedTest Environment: Vector implementation(N=2,T=int64)testset: fill3/3 tests passedTest Environment: Vector implementation(N=3,T=int64)testset: fill4/4 tests passed