无法运行Junit测试

时间:2018-06-07 16:02:07

标签: java spring maven intellij-idea junit

我已经构建了webservice代码。我在其中为restController添加了一个Junit测试用例。

我把命令弄为

mvn -Dtest="completed package"+classname test

错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.8.1:test (default-test) on project isi-service: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.8.1:test (default-test) on project iamsi-service: No te
sts were executed!  (Set -DfailIfNoTests=false to ignore this error.)

我的课程:

@RunWith(SpringRunner.class)
@SpringBootTest
public class ITokenServiceHandlerBase  {

    @InjectMocks
    private ITokenServiceHandlerBase   iTokenServiceHandlerBase  ;
    private MockMvc mockMvc;
    @Before
    public void setUp() throws Exception{
        mockMvc = MockMvcBuilders.standaloneSetup(iTokenServiceHandlerBase )
                .build();
    }

    @Test
    public void handleGet() throws Exception {
        mockMvc.perform(
                MockMvcRequestBuilders.get(Constants.IM_TOKEN_API_V1)
        ).andExpect(MockMvcResultMatchers.status().isOk());
    }
}

使用Intellij运行测试菜单:

  

" C:\ Program Files \ Java \ jdk1.8.0_121 \ bin \ java.exe"   -Dvisualvm.id = 21230012706744 -ea -Didea.test.cyclic.buffer.size = 1048576" -javaagent:C:\ Program Files \ JetBrains \ IntelliJ IDEA Community Edition   2018.1.4 \ lib \ idea_rt.jar = 60543:C:\ Program Files \ JetBrains \ IntelliJ IDEA Community Edition 2018.1.4 \ bin" -Dfile.encoding = UTF-8 -classpath   " C:\ Program Files \ JetBrains \ IntelliJ IDEA社区版   2018.1.4 \ lib \ idea_rt.jar; C:\ Program Files \ JetBrains \ IntelliJ IDEA Community Edition 2018.1.4 \ plugins \ junit \ lib \ junit-rt.jar; C:\ Program   Files \ JetBrains \ IntelliJ IDEA社区版   2018.1.4 \ plugins \ junit \ lib \ junit5-rt.jar; C:\ Program Files \ Java \ jdk1.8.0_121 \ jre \ lib \ charsets.jar; C:\ Program   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ deploy.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\访问桥64.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ cldrdata.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ dnsns.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ jaccess.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ jfxrt.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ localedata.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ nashorn.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ sunec.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\程序(sunjce_provider.jar); C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ sunmscapi.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ sunpkcs11.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ lib中\分机\ zipfs.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ javaws.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ jce.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ jfr.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ jfxswt.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ jsse.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \管理-agent.jar中; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ plugin.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ resources.jar; C:\ PROGRAM   文件\的Java \ jdk1.8.0_121 \ JRE \ LIB \ rt.jar的; C:\用户\ yogendra.singh2.m2 \库\ COM \皮尔森\ GLP \客户横切\ 0.33.1 \客户横切-0.33。 1.jar; C:\用户\ yogendra.singh2.m2 \库\ COM \皮尔森\平台\共同\ 0.33.4 \共0.33.4.jar; C:\用户\ yogendra.singh2.m2 \库\ COM \皮尔森\平台\ utils的\ 0.33.4 \ utils的-0.33.4.jar; C:\用户\ yogendra.singh2.m2 \库\组织\ springframework的\弹簧豆\ 4.3.15.RELEASE \弹簧豆-4.3.15.RELEASE.jar; C:\用户\ yogendra.singh2.m2 \库\有机\ springframework的\弹簧核\ 4.3.15.RELEASE \弹簧芯4.3.15.RELEASE.jar; C: \用户\ yogendra.singh2.m2 \库\有机\ springframework的\弹簧的web \ 4.3.15.RELEASE \弹簧网络4.3.15.RELEASE.jar; C:\用户\ yogendra.singh2.m2 \库\ IO \招摇\招摇的注解\ 1.5.10 \招摇的注解-1.5.10.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\蚂蚁1.9.4.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\蚂蚁ANTLR-1.9.4.jar; C: \用户\ yogendra .singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\蚂蚁的junit-1.9.4.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-sdk- 2.4.15 \常规-2.4.15 \ lib中\蚂蚁发射-1.9.4.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ BSF-2.4.0.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\公地-CLI-1.2.jar; C:\用户\ yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\共享记录-1.2.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-sdk- 2.4.15 \常规-2.4.15 \ lib中\ gpars-1.2.1.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\常规-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\常规-ANT-2.4.15.jar; C:\用户\ yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ Groovy的BSF-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的groovy- SDK-2.4.15 \常规-2.4.15 \ lib中\ Groovy的控制台2.4.15.jar; C:\用户\ yogendra.singh2 \ Downloa DS \ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ Groovy的docgenerator-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ Groovy的GroovyDoc的-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ groovy- groovysh-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ Groovy的JMX-2.4.15.jar; C:\用户\ yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ Groovy的JSON-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-sdk-2.4.15 \常规-2.4.15 \ lib中\常规-jsr223-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4。 15 \ lib中\常规-NIO-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ Groovy的servlet的2.4.15的.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\常规-SQL 2.4.15.jar; C:\用户\ yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ Groovy的摆动2.4.15.jar; C: \ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\常规的模板-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ apache-常规-SDK-2.4.15 \常规-2.4.15 \ lib中\常规试验2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4 0.15 \ lib中\ Groovy的TestNG的-2.4.15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\常规的XML-2.4。 15.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ hamcrest核-1.3.jar; C:\用户\ yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\常春藤2.4.0.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ jansi-1.11.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ jcommander-1.47.jar; C: \ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\的JLine-2.12.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-sdk- 2.4.15 \常规-2.4.15 \ lib中\ JSP的API-2.0.jar; C:\用户\ yogendra.sing H2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ jsr166y-1.7.0.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\的junit-4.12.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\多元宇宙核-0.7。 0.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ qdox-1.12.1.jar; C:\用户\ yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ servlet的API-2.4.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ TestNG的-6.8.13.jar; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ xmlpull-1.1.3.1。罐; C:\ Users \用户yogendra.singh2 \下载\ Apache的常规-SDK-2.4.15 \常规-2.4.15 \ lib中\ XStream的-1.4.10.jar; C:\用户\ yogendra.singh2.m2 \库\有机\ springframework的\弹簧测试\ 4.3.15.RELEASE \弹簧测试4.3.15.RELEASE.jar; C:\用户\ yogendra.singh2.m2 \库\有机\ powermock \ powermock核\ 1.6 0.6 \ powermock核-1.6.6.jar; C:\用户\ yogendra.singh2.m2 \重新pository \有机\ springframework的\引导\弹簧引导检验\ 1.5.11.RELEASE \弹簧引导测试1.5.11.RELEASE.jar; C:\用户\ yogendra.singh2.m2 \库\有机\ springframework的\云\弹簧云合同验证\ 1.2.3.RELEASE \弹簧云合同验证-1.2.3.RELEASE.jar; C:\用户\ yogendra.singh2.m2 \库\有机\的Mockito \的Mockito芯\ 19年1月10日\的Mockito核-1.10.19.jar; C:\用户\ yogendra.singh2.m2 \库\ CH \的QoS \的logback \的logback核\ 1.1.11 \的logback核-1.1 .11.jar"   com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4   com.platform.iam.servicehandler.ImTokenApiServiceHandlerBase,handleGet

     

流程已完成退出代码1未找到类:" com.platform.iam.servicehandler.ImTokenApiServiceHandlerBase"清空   测试套件。

1 个答案:

答案 0 :(得分:0)

由于Class名称本身,Maven在构建过程中可能会遇到识别JUnit测试的问题。

尝试使用"测试"的后缀重命名您的类,例如" iTokenServiceHandlerBaseTest"。