Unit testing my ops

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!


1 Like

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.

1 Like

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?

Hi @alessandrofelder and @bnorthan,

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


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:


Thanks a lot @imagejan,

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


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.