JUnit测试套件中没有可运行的方法(初始化错误)

b91juud3  于 2022-11-11  发布在  其他
关注(0)|答案(1)|浏览(155)

我试图用我的3个测试类实现JUnit测试套件,并同时运行它们。但是当我运行那个测试套件时,它给我错误,如初始化错误和“没有找到可运行的方法”。
这是我的测试套件类,名为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 {

}

这是一个JUnitTesting_AddPatientPage类

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);   
    }

}

这是我的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);
    }
}

这是我的JUnitTesting登录页面

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); 
    }
}

在运行ALLTests.java作为JUnit测试后,它给予我以下错误:-

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)

任何帮助都将不胜感激!

lfapxunr

lfapxunr1#

这种错误消息通常意味着您混淆了JUnit 4和JUnit 5。
实际上,如果您仔细查看堆栈跟踪,就会发现您正在使用JUnit 4 runner来运行JUnit 5测试。

相关问题