Unit testing my ops

bonej
imagej-ops
unit-tests

#1

Hi everyone,

I have written a op for BoneJ that includes a unit test for it.

My op uses some imagej-ops (maths and morphology for example), so, if I understand correctly, my unit test class needs an instantiate a Context with an OpService for the class it is testing. I have seen that within the imagej-ops package there is an AbstractOpTest class that takes care of this.

This may be a very basic Java question: is it possible for me to extend the AbstractOpTest class from outside the imagej-ops package (say from within the bonej-ops package which depends on imagej-ops)?

Thanks for any advice!

Best,
Alessandro


#2

Hi @alessandrofelder

It’s possible to extend AbstractOpTest however you have to import the test artifact (a jar with a name something like imagej-ops-0.XX.X-tests.jar. As far as I can tell that artifact is not in a public maven repository. Though I’m no maven expert so it’s quite possible I’m missing something obvious. In that case hopefully someone more knowledgeable can tell us where to find it.

That being said, you could build imagej-ops locally then reference the local copy of imagej-ops-X.XX.X-SNAPSHOT-tests.jar.

see this example pom.

and this class.

The problem is that in order for this project to build, it now needs version 0.43.3 of ops built locally. So this isn’t really a great solution. Hopefully others will have some suggestions. It would be nice to be able to easily extend AbstractOpTest outside the imagej-ops project.


#3

Thanks very much for your thoughts, Brian!

I agree. I am no maven expert either… and I don’t really want to complicate the set up for the BoneJ development by adding dependencies to local builds. Maybe, as you say, someone else has another solution?


#4

Hi @alessandrofelder and @bnorthan,

the ImageJ maven repository hosts all the relevant jar files, also imagej-ops-tests.jar:

http://maven.imagej.net/#nexus-search;quick~imagej-ops

I haven’t tested it, but you should be able to use AbstractOpTest by depending on imagej-ops like proposed in the Maven tab of the respective jar file:

<dependency>
  <groupId>net.imagej</groupId>
  <artifactId>imagej-ops</artifactId>
  <version>0.43.2</version>
  <classifier>tests</classifier>
</dependency>

#5

Thanks a lot @imagejan,

I will try on Thursday when I am back from annual leave and report results here.

Alessandro


#6

Thanks @imagejan

I think I got confused becase a) there doesn’t seem to be a ‘managed’ version of imagej-ops-tests (you need to explicitly define a version number) and I was looking for 0.43.3, which isn’t there yet.

Anyway I did confirm that referencing imagej–ops-tests as you propose does work, and my test example should now build without having to also build a local copy of imagej-ops.