Created
August 9, 2012 07:19
-
-
Save ahitrin/3301925 to your computer and use it in GitHub Desktop.
JUnit Theories usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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