I have several junit test cases that extend an AbstractTest. They’re all required to have a static method suite(). However people usually copy&paste old test case to make new one, and they end up forgetting to change the old OtherTest.class to the new one TestA.class. This is bad because the new test will not run, and this is very hard to detect, because there is no compile error.
public class TestA{
public static junit.framework.Test suite() {
return new junit.framework.JUnit4TestAdapter(
OtherTest.class);// Should be TestA.class
}
}
Is there a way to write something like
return new junit.framework.JUnit4TestAdapter(this);
If the above is not possible, are there any other ways to at least mark this type of error?
A further variation:
The advantage of this is that you can separate the SecurityManager from the class you’re using it in, i.e., you can have only one instance of it somewhere and use it to obtain interesting reflective metadata, including this one. Without any special ugliness about it. The reason a plain
SecurityManagerdoesn’t work here is thatgetClassContextisprotected.edit: further example