[squeak-dev] Porting JUnit's Theories to SUnit?
frank.shearar at gmail.com
Mon Jul 11 14:02:49 UTC 2011
Has anyone looked into porting JUnit 4's Theories into SUnit? (NUnit
also uses theories, in 2.5)
In brief, a Theory is a test that takes a parameter. So what before might say
-1 to: 1 do: [:i | self assert: i myFoo = i printString
description: 'Failure for integer ', i printString]
self assert: anInteger myFoo = anInteger printString description:
'Failure for integer ', anInteger printString
You define a bunch of DataPoints, and then the runner runs that test
for every data point. In JUnit data points are defined through
constants with @DataPoint/@DataPoints annotations, but of course we
can do them however we want. Further, theories can make assumptions,
which are essentially pretest filters. For instance, in a TestCase
dealing with real algebra, a test for square roots might say
self assumeThat: [anInteger > 0].
"Rest of test"
and then the test would only run on positive data points.
The essential idea is simply decoupling the test itself - the theory -
from the data, so you don't have to roll your own looping construct
when testing multiple data points.
More information about the Squeak-dev