当前位置:  开发笔记 > 编程语言 > 正文

为什么@Ignore注释不起作用?

如何解决《为什么@Ignore注释不起作用?》经验,为你挑选了1个好方法。

同事,我的测试课中有@ignore批注 AppTest.java.

     import java.math.BigInteger;
    import java.util.UUID;

    import org.fluttercode.datafactory.impl.DataFactory;
    import org.junit.Ignore;
    import org.junit.Test;

    import junit.framework.TestCase;

public class AdapterAppTest extends TestCase {    
    @Ignore("this test is not ready yet")
        public static void testCreateApplicationWithAllRequiredParameters() {

            AdapterApp.setWsURL(URL);

            AdapterApp adapterApp = new AdapterApp(); 
            System.out.println("Set UP Request Parameters");

            DataFactory df = new DataFactory();

            adapterApp.setRequestTimestamp("2015-12-01T12:12:12.123"));
            adapterApp.setRequestUid(UUID.randomUUID().toString());
            adapterApp.setProductType("0");


            String applicationNum = adapterApp.createApplication();
            assertEquals("2 symb", 2, applicationNum.length());
        } 
}

我的pom看起来:



    org.springframework
    spring-context
    4.2.3.RELEASE



    org.springframework
    spring-core
    4.2.3.RELEASE




    junit
    junit
    4.12




    io.codearte.jfairy
    jfairy
    0.5.1




    org.fluttercode.datafactory
    datafactory
    0.8




    org.springframework.ws
    spring-ws-core
    2.2.3.RELEASE



    log4j
    log4j
    1.2.17



    org.apache.httpcomponents
    httpclient
    4.5.1





    xerces
    xercesImpl
    2.11.0




    
        org.apache.maven.plugins
        maven-compiler-plugin
        3.3
        
            ${jdk.version}
            ${jdk.version}
            UTF-8
        
    


    
        org.apache.maven.plugins
        maven-surefire-plugin
        2.19
            
            
                
                    test
                
            
        


        
            
                org.apache.maven.surefire
                surefire-junit47
                2.19
            
        

        
            
                AdapterAppTest.java
            
        
    




    
        org.apache.maven.plugins
        maven-jar-plugin
        2.6
        
            
                
                    com.adapter
                
            
        
    



    
        maven-assembly-plugin
        
            
                
                    com.adapter
                
            
            
                jar-with-dependencies
            
        
    


    
        org.jvnet.jaxb2.maven2
        maven-jaxb2-plugin
        0.13.0
        
            
                
                    generate
                
            
        
        
            WSDL
            com.adapter_entities
            
                
                    src/main/resources/Import.wsdl
                
            

        
    




结果,我收到:

[INFO]扫描项目... [INFO] [INFO] ----------------------------------- ------------------------------------- [INFO]建筑适配器0.0.1-SNAPSHOT [INFO] -------------------------------------------------- ---------------------- [INFO] [INFO] --- maven-jaxb2-plugin:0.13.0:generate(默认)@ adapter- [INFO]源资源的最新检查[INFO] [INFO] --- maven-resources-plugin:2.6:resources(default-resources)@适配器--- [INFO]使用'UTF-8'编码复制过滤的资源。[INFO]复制3个资源[INFO]复制1个资源[INFO] [INFO] --- maven-compiler-plugin:3.3:compile(default-compile)@ adapter --- [INFO]检测到更改-重新编译模块![INFO]将25个源文件编译到C:\ Users \ git \ adapter \ adapter \ target \ classes [INFO] [INFO] --- maven-resources-plugin:2.6:testResources(default-testResources)@适配器--- [INFO]使用'UTF-8'编码复制过滤的资源。[INFO]跳过不存在的resourceDirectory C:\ Users \ git \ adapter \ adapter \ src \ test \ resources [INFO] [INFO] --- maven-compiler-plugin:3.3:testCompile(default-testCompile)@适配器- -[信息]无需编译-所有类都是最新的[信息] [信息] --- maven-surefire-plugin:2.19:test(默认测试)@适配器---

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.adapter.AdapterAppTest

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.546 sec - in com.adapter.AdapterAppTest

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-surefire-plugin:2.19:test (default) @ adapter ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.452 s
[INFO] Finished at: 2015-12-03T16:09:13+03:00
[INFO] Final Memory: 25M/413M
[INFO] ------------------------------------------------------------------------

为什么@Ignore注释无效?



1> Jens Schaude..:

您仅显示了代码的一小部分,但据我所知,我怀疑您正在使用JUnit3(从Testcase扩展并通过“ test”前缀标识测试方法。

忽略注释仅适用于JUnit 4 Test,即:

测试方法用@Test注释,并且该类不继承自TestCase

使用现在发布的代码,将测试的开始更改为:

public class AdapterAppTest {    
    @Test     
    @Ignore("this test is not ready yet")
    public static void testCreateApplicationWithAllRequiredParameters() {

推荐阅读
贾志军
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有