Skip to main content

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 implementation

testset: fill(N=2,T=int32)
3/3 tests passed

testset: fill(N=3,T=int32)
4/4 tests passed

testset: fill(N=2,T=int64)
3/3 tests passed

testset: 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: fill
3/3 tests passed

Test Environment: Vector implementation(N=3,T=int32)

testset: fill
4/4 tests passed

Test Environment: Vector implementation(N=2,T=int64)

testset: fill
3/3 tests passed

Test Environment: Vector implementation(N=3,T=int64)

testset: fill
4/4 tests passed