Skip to content

Instantly share code, notes, and snippets.

@ahitrin
Created August 9, 2012 07:19
Show Gist options
  • Save ahitrin/3301925 to your computer and use it in GitHub Desktop.
Save ahitrin/3301925 to your computer and use it in GitHub Desktop.
JUnit Theories usage
bb+1
bb+2
bb+100
ccc+1
ccc+2
ccc+100
a, a
a, bb
a, ccc
bb, a
bb, bb
bb, ccc
ccc, a
ccc, bb
ccc, ccc
import static org.junit.Assume.assumeTrue;
import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
/**
* See http://blog.schauderhaft.de/2010/01/31/new-feature-of-junit-theories/
* and http://blog.schauderhaft.de/2010/02/07/junit-theories/
* for more examples on theories
*/
@RunWith(Theories.class)
public class TTest
{
@DataPoints
public static String[] strings = {"a", "bb", "ccc"};
@DataPoints
public static Integer[] integers = {1, 2};
@DataPoint
public static Integer unexpected = 100;
@Theory
public void allVariations(String s, Integer i) {
assumeTrue(s.length() > 1);
System.out.println(s + "+" + i);
}
@Theory
public void onlyStrings(String a, String b) {
System.out.println(a + ", " + b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment