Skip to content

Instantly share code, notes, and snippets.

@psenger
Last active March 2, 2020 21:39
Show Gist options
  • Save psenger/329591 to your computer and use it in GitHub Desktop.
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
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
{
}
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 );
}
}
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