Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Runnable methods Error From Base Test class

I have a A few base test classes that setup common configurations for spring,logging,jndi etc using test execution listeners that are then inherited by subclasses. This is done so tests can just run code without having to worry about getting jndi and logging services in place before being able to run testing code.

Using intellij and invoking "run all tests" from the project base, the IDE attempts to run the base test class as a unit test and gives me the "No runnable methods" error.

I know I could put an empty runnable method in the base class, but I was hoping some one has a better idea.

The Base class is:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {
            "classpath:spring-jndi.xml"
    })
    @TestExecutionListeners({
            Log4JSetupListener.class,
            JndiSetupListener.class,
            DependencyInjectionTestExecutionListener.class,
            DirtiesContextTestExecutionListener.class,
            TransactionalTestExecutionListener.class
    })
    public class SpringAppTestCase extends Assert implements ApplicationContextAware {

        protected JndiTemplate jndiTemplate = new JndiTemplate();

        @Autowired
        protected JdbcTemplate jdbcTemplate;

        protected ApplicationContext applicationContext;

        public void setApplicationContext(ApplicationContext ac) {
            this.applicationContext = ac;
        }

    // 
    //    @Test
    //    public void doit(){
    //      // this would prevent blow up but 
    // all subclass tests would run an extra method
    //    }

        protected Logger log = Logger.getLogger(getClass().getName());

}

The error:

java.lang.Exception: No runnable methods
    at org.junit.internal.runners.MethodValidator.validateInstanceMethods(MethodValidator.java:32)
    at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:43)
    at org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4ClassRunner.java:36)
    at org.junit.internal.runners.JUnit4ClassRunner.<init>(JUnit4ClassRunner.java:27)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:76)
like image 787
gbegley Avatar asked Jun 10 '09 17:06

gbegley


2 Answers

Make the parent class abstract or rename it such as it does not end in Test or TestCase.

like image 168
Robert Munteanu Avatar answered Oct 15 '22 17:10

Robert Munteanu


making sure the @Test annotation import is org.junit.Test and not something else like juniper which i saw as a comment by here worked for me. Wanted to add this as an answer so it can be seen by others

like image 12
akinmail Avatar answered Oct 15 '22 19:10

akinmail