scijava-common icon indicating copy to clipboard operation
scijava-common copied to clipboard

Consider creating scijava-test repository with common junit test utils

Open imagejan opened this issue 5 years ago • 2 comments

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.

imagejan avatar Jan 14 '20 13:01 imagejan

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>

ctrueden avatar Jan 14 '20 19:01 ctrueden

Ah, we do have AbstractSciJavaTest already, but it doesn't appear to be used anywhere in the codebase I searched.

imagejan avatar Dec 21 '20 08:12 imagejan