JUnit 测试套件中没有可运行的方法(初始化错误)
No runnable method in JUnit test Suites (Initialization error)
我正在尝试同时使用我的 3 测试 类 和 运行 来实施 JUnit 测试套件。
但是每当我 运行 该测试套件时,它都会给我错误作为初始化错误,“找不到 运行 可用方法。”
这是我的测试套件 class 命名为 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.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);
}
}
这是我的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_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);
}
}
在 运行ning 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)
任何帮助将不胜感激!
这种错误消息通常意味着您混淆了 JUnit 4 和 JUnit 5。
事实上,如果您仔细查看堆栈跟踪,您会发现您正在使用 JUnit 4 运行ner 来进行 运行 JUnit 5 测试。
我正在尝试同时使用我的 3 测试 类 和 运行 来实施 JUnit 测试套件。 但是每当我 运行 该测试套件时,它都会给我错误作为初始化错误,“找不到 运行 可用方法。”
这是我的测试套件 class 命名为 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.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);
}
}
这是我的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_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);
}
}
在 运行ning 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)
任何帮助将不胜感激!
这种错误消息通常意味着您混淆了 JUnit 4 和 JUnit 5。
事实上,如果您仔细查看堆栈跟踪,您会发现您正在使用 JUnit 4 运行ner 来进行 运行 JUnit 5 测试。