10
I would like my JUnit4 Tests to be executed according to a custom annotation that I created with Java. The purpose of this custom annotation is for JUnit4 to note that the test should only be run if the machine's platform matches the one specified in the annotation.
Say I have the following annotation:
public @interface Annotations {
String OS();
...
}
And the following Tests:
public class myTests{
@BeforeClass
public setUp() { ... }
@Annotations(OS="mac")
@Test
public myTest1() { ... }
@Annotations(OS="windows")
@Test
public myTest2() { ... }
@Annotation(OS="unix")
@Test
public myTest3() { ... }
}
If I were to execute these tests in a Mac machine, then only myTest1() should be executed and the rest should be ignored. However, I am currently stuck on how I should implement this. How do I let JUnit read my custom annotation and check whether the test should be run or not.