mikera
mikera

Reputation: 106351

Inheritable "Generic" JUnit 4 test suite

I'd like to create a "generic" JUnit 4 test that can be used as follows:

The motivation for this is that the class defines a standard test procedure that may be useful in many different projects, but require some customisation by the user in each case.

Is this possible with JUnit 4, and if so how should I do it?

Upvotes: 0

Views: 268

Answers (2)

Avner Levy
Avner Levy

Reputation: 6741

Perhaps this can provide you a starting point: Writing base class for your tests.
Just pack it as every other class in a jar and you are ready to go.

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691735

Yes it's possible. You would simply have to create your abstract class, package it in a jar, give this jar to the users or store it somewhere where they can download it.

Users would then put the jar in their own project and create subclasses of your abstract class. They would use their IDEs (or any other way) to run these test classes extending your abstract class, and the IDE would display the result of all the tests, typically using a tree.

This looks like a repetition of everything you asked in your question, but the way to do it is just as you have explained in your question. There's not much to add.

Upvotes: 1

Related Questions