Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot java.lang.Exception:没有可运行的方法junit springboot2_Spring Boot_Junit4_Junit5 - Fatal编程技术网

Spring boot java.lang.Exception:没有可运行的方法junit springboot2

Spring boot java.lang.Exception:没有可运行的方法junit springboot2,spring-boot,junit4,junit5,Spring Boot,Junit4,Junit5,我正在为springboot应用程序编写Junits。当我运行junit时,我发现没有方法可以运行。下面是代码 朱尼特: @RunWith(Suite.class) @SuiteClasses({EmployeeServiceApplication.class}) 公共类TestEmployeeService{ @嘲弄 雇员安置方案; @自动连线 员工服务; @之前 void setMockOutput(){ HashSet empSet=新HashSet(); 增加(新员工视图(1,“姓氏”、

我正在为springboot应用程序编写Junits。当我运行junit时,我发现没有方法可以运行。下面是代码 朱尼特:

@RunWith(Suite.class)
@SuiteClasses({EmployeeServiceApplication.class})
公共类TestEmployeeService{
@嘲弄
雇员安置方案;
@自动连线
员工服务;
@之前
void setMockOutput(){
HashSet empSet=新HashSet();
增加(新员工视图(1,“姓氏”、“姓氏”、“1986年5月30日”、“EE”);
when(emprep.getEmployeeList()).thenReturn(empSet);
}
@试验
public void testGetEmployeeList(){
Assert.notEmpty(service.getEmployeeList());
}
pom.xml:


4.0.0
org.springframework.boot
spring启动程序父级
2.2.1.发布
com.employeeService
雇员服务
0.0.1-快照
雇员服务
SpringBoot的演示项目
1.8
org.springframework.boot
SpringBootStarterWeb
伊奥·斯普林福克斯
springfox-Swagger 2
2.4.0
伊奥·斯普林福克斯
springfox招摇过市用户界面
2.4.0
org.springframework.boot
弹簧起动试验
测试
org.springframework.boot
springbootmaven插件
我错过什么了吗? 我尝试了stackoverflow的很多选项,但都不起作用。下面是我尝试过的东西 1.SpringBootTest 2.模拟跑步者 3.@SpringBootTest(类)

堆栈跟踪:

java.lang.Exception: No runnable methods
    at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
    at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
    at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
    at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:101)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:87)
    at org.junit.runners.Suite.<init>(Suite.java:102)
    at org.junit.runners.Suite.<init>(Suite.java:70)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    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:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:84)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:70)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
您将JUnit4(RunWith)与JUnit5(beforeach)混合在一起。我猜测试注释来自JUpiter/JUnit5,这就是为什么运行程序找不到任何测试方法的原因


您必须坚持使用JUnit4或Jupiter。注意您的导入!

使用import org.junit.Test重新导入;删除Jupiter导入修复了问题

是否存在堆栈跟踪?确保测试类位于src/Test/java文件夹中。@MariosNikolaou是的,该类位于“src/Test/java”中@aventurin更新了stacktraceOK,似乎是JUnit4。我尝试删除@beforeach,但它无法显示所有导入。在问题中添加了导入每个导入都带有“jupiter”“在这方面,它不会与RunWith一起工作;请改用org.junit.Test和org.junit.Before。此外,对于spring测试,您可能需要一个SpringRunner,但我不是这方面的专家。也许可以作为一个起点。这正是我的问题,使用
import org.junit.Test;
重新导入并删除jupiter导入修复了这个问题M
package com.employeeService.employeeService.service;

import static org.mockito.Mockito.when;

import java.util.HashSet;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;

import com.employeeService.employeeService.EmployeeServiceApplication;
import com.employeeService.employeeService.service.repository.EmployeeRepository;