How can I split abstract testcases in JUnit?

Posted by Willi Schönborn on Stack Overflow See other posts from Stack Overflow or by Willi Schönborn
Published on 2010-02-17T21:58:26Z Indexed on 2010/03/09 4:21 UTC
Read the original article Hit count: 194

Filed under:
|
|
|
|

I have an abstract testcase "AbstractATest" for an interface "A". It has several test methods (@Test) and one abstract method:

protected abstract A unit();

which provides the unit under testing. No i have multiple implementations of "A", e.g. "DefaultA", "ConcurrentA", etc.

My problem: The testcase is huge (~1500 loc) and it's growing. So i wanted to split it into multiple testcases. How can organize/structure this in Junit 4 without the need to have a concrete testcase for every implementation and abstract testcase.

I want e.g. "AInitializeTest", "AExectueTest" and "AStopTest". Each being abstract and containing multiple tests. But for my concrete "ConcurrentA", i only want to have one concrete testcase "ConcurrentATest".

I hope my "problem" is clear.

EDIT
Looks like my description was not that clear.
Is it possible to pass a reference to a test?
I know parameterized tests, but these require static methods, which is not applicable to my setup. Subclasses of an abstract testcase decide about the parameter.

© Stack Overflow or respective owner

Related posts about java

Related posts about junit