scijava-common
scijava-common copied to clipboard
Consider creating scijava-test repository with common junit test utils
In many SciJava components, we have lines like those in tests:
private Context context;
@Before
public void setUp() {
context = new Context();
}
@After
public void tearDown() {
context.dispose();
}
... to set up and tear down a SciJava context. We might want to create a JUnit TestRule for this, such as:
public class TestContext extends ExternalResource implements TestRule {
... set up Context here ...
}
so that in the tests, you can write:
@Rule
TestContext context = new TestContext();
and can omit the setUp() and tearDown() methods.
This would have to go in its own repository scijava-test though, so it's maybe not worth the effort for just this case. But maybe others have ideas what other test utilities could live in a common repository.
Hmm, interesting. Why would it need to go in its own repository? The scijava-common project does have some reusable test infrastructure in its own test scope, which you can use by adding a dependency as follows:
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-common</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Ah, we do have AbstractSciJavaTest already, but it doesn't appear to be used anywhere in the codebase I searched.