Skip to content
Advertisement

No runnable method in JUnit test Suites (Initialization error)

I am trying to implement JUnit TestSuites with my 3 Test Classes and run them at the same time. But when ever I run that test suite it gives me error as Initialization Error with “No runnable method found.”

This is my test Suite class named as AllTests.java

package Calendar.CalendarTesting;

import org.junit.runner.RunWith;

import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({JUnitTesting_AddPatientPage.class, JUnitTesting_DentalCategoryPage.class, JUnitTesting_LoginPage.class})
public class AllTests {

}

This is JUnitTesting_AddPatientPage.class

package Calendar.CalendarTesting;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;

import org.junit.jupiter.api.Test;

public class JUnitTesting_AddPatientPage {

    AddPatient addPatientPage = new AddPatient();
    public  JUnitTesting_AddPatientPage()
    {}
    
    @Test
    public void SpecialityButtonGroupClearCheck() {
        assertEquals(null, AddPatient.Speciality.getSelection());
    }
    
    @Test
    public void PatientNameCheck() {
        assertNotEquals(null, addPatientPage.pnameTextField);   
    }

    @Test
    public void PatientAgeNullCheck() {
        assertNotEquals(null, addPatientPage.pageTextField);    
    }
    
    @Test
    public void PatientAgeValidCheck() {
        assertNotEquals(0, addPatientPage.pageTextField);   
    }
    
}

This is my JUnitTesting_DentalCategoryPage.class

package Calendar.CalendarTesting;
import static org.junit.Assert.assertEquals;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class JUnitTesting_DentalCategoryPage {

    DentalCategory dentalcategorypage = new DentalCategory("A", 58, "Dental");
    
    @Test
    public void CategoryButtonGroupClearCheck() {
        assertEquals(null, DentalCategory.Category.getSelection());
    }
    
    @Test
    public void RoutingDentalCheck() {
        assertEquals("Dental", dentalcategorypage.pspeciality);
    }
    
    @Test
    public void InitalRatingCheck() {
        assertEquals(0, dentalcategorypage.rating);
    }
}

This is my JUnitTesting_LoginPage

package Calendar.CalendarTesting;
import static org.junit.Assert.assertEquals;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

public class JUnitTesting_LoginPage {

    LoginTest loginPage = new LoginTest();
        
    @Test
    public void LoginButtonDisableCheck() {
        assertEquals(false, loginPage.loginButton.isEnabled());
    }
    
    @Test
    public void ViewPasswordButtonDisableCheck() {
        assertEquals(false, loginPage.showPassword.isSelected());
    }
    
    @Test
    public void LoginNameCheck() {
        assertNotEquals(null, loginPage.usernameTextField); 
    }

    @Test
    public void LoginPasswordCheck() {
        assertNotEquals(null, loginPage.passwordField); 
    }
}

After running ALLTests.java as JUnit test it give me following error :-

org.junit.runners.model.InvalidTestClassError: Invalid test class 'Calendar.CalendarTesting.JUnitTesting_AddPatientPage':
  1. No runnable methods
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:525)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:102)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:84)
    at org.junit.runners.JUnit4.<init>(JUnit4.java:23)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:125)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:111)
    at org.junit.runners.Suite.<init>(Suite.java:102)
    at org.junit.runners.Suite.<init>(Suite.java:70)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:107)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
    at org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
    at org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)

Any help will be appreciated!

Advertisement

Answer

This kind of error message usually means you are mixing up JUnit 4 and JUnit 5.

In fact, if you look closer at your stacktrace you will find that you are using a JUnit 4 runner to run JUnit 5 tests.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement