Reputation: 488
I have two classes:
public abstract class AbstractFoobar { ... }
and
public class ConcreteFoobar extends AbstractFoobar { ... }
I have corresponding test classes for these two classes:
public class AbstractFoobarTest { ... }
and
public class ConcreteFoobarTest extends AbstractFoobarTest { ... }
When I run ConcreteFoobarTest (in JUnit), the annotated @Test methods in AbstractFoobarTest get run along with those declared directly on ConcreteFoobarTest because they are inherited.
Is there anyway to skip them?
Upvotes: 2
Views: 2637
Reputation: 1
Using process tags would allow you to run into specific bodies of code
Upvotes: 0
Reputation: 299218
Update: Misunderstood the Question
AbstractFoobarTest
abstract.
That way the test methods in
AbstractFoobarTest
are only run
once, when ConcreteFoobarTest
is
executed. You are going to need a
concrete subclass to test the
methods in AbstractFoobar
anyway.AbstractFoobartest
and
ConcreteFoobarTest
. You don't want
to make use of it anyway.Upvotes: 1
Reputation: 40176
You really don't need AbstractFoobarTest
in the first place because after all you can't create an instance of the abstract class, so, you will still rely on your concrete class to test your abstract class.
That means, you will end up using your ConcreteFoobarTest
will test the APIs from the abstract class. Thus, you will have just this:-
public class ConcreteFoobarTest { ...
@Test
public void testOne() {
ConcreteFoobar cf = new ConcreteFoobar();
// assert cf.conreteAPI();
}
@Test
public void testTwo() {
ConcreteFoobar cf = new ConcreteFoobar();
// assert cf.abstractClassAPI();
}
}
Upvotes: 1