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 d开发者_高级运维eclared directly on ConcreteFoobarTest because they are inherited.
Is there anyway to skip them?
Update: Misunderstood the Question
- Make
AbstractFoobarTest
abstract. That way the test methods inAbstractFoobarTest
are only run once, whenConcreteFoobarTest
is executed. You are going to need a concrete subclass to test the methods inAbstractFoobar
anyway. - Or just remove the inheritance
between
AbstractFoobartest
andConcreteFoobarTest
. You don't want to make use of it anyway.
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();
}
}
Using process tags would allow you to run into specific bodies of code
精彩评论