Last active
March 2, 2020 21:39
-
-
Save psenger/329591 to your computer and use it in GitHub Desktop.
[Example bug of Junit 4.8.1 regarding Categories and multiple BeforeClass Annotations] #Java
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 org.junit.runner.*; | |
import org.junit.experimental.categories.*; | |
import org.junit.runners.*; | |
/** | |
* For use with testing a bug with Junit 4.8.1 | |
**/ | |
@RunWith(Categories.class) | |
@Categories.IncludeCategory(Development.class) | |
@Suite.SuiteClasses({MytestClass.class}) | |
public class Development | |
{ | |
} |
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 org.junit.experimental.categories.*; | |
import org.junit.*; | |
/** | |
* For use with testing a bug with Junit 4.8.1 | |
**/ | |
public class MytestClass | |
{ | |
private static String color = null; | |
/** | |
* Looks like the BeforeClass is not subject to the Categories strategy. | |
**/ | |
@Category({Development.class}) | |
@BeforeClass | |
public static void setupAllTestsDev() | |
{ | |
color = "red"; | |
} | |
/** | |
* Looks like the BeforeClass is not subject to the Categories strategy. | |
**/ | |
@Category({Stage.class}) | |
@BeforeClass | |
public static void setupAllTestsStage() | |
{ | |
color = "blue"; | |
} | |
@Category({Stage.class}) | |
@Test | |
public void testStageColor () { | |
Assert.assertEquals("The color is not blue", "blue", color ); | |
} | |
@Category({Development.class}) | |
@Test | |
public void testDevColor () { | |
Assert.assertEquals("The color is not red", "red", color ); | |
} | |
} |
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 org.junit.runner.*; | |
import org.junit.experimental.categories.*; | |
import org.junit.runners.*; | |
/** | |
* For use with testing a bug with Junit 4.8.1 | |
**/ | |
@RunWith(Categories.class) | |
@Categories.IncludeCategory(Stage.class) | |
@Suite.SuiteClasses({MytestClass.class}) | |
public class Stage | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment