资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Java中@Category注解的工作原理是什么-创新互联

今天就跟大家聊聊有关Java中@Category注解的工作原理是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联公司长期为近1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为若羌企业提供专业的成都网站制作、成都做网站,若羌网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。

(1) Create empty class FastTests and SlowTests. (2) In your test case class, categorize your test method using @Category annotation:

Java中@Category注解的工作原理是什么

(3) Append the following code to your pom.xml:


        
            SlowTests
            
                com.sap.SlowTests
            
        
        
            FastTests
            
                com.sap.FastTests
            
        
    
    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                3.1
                
                    1.8
                    1.8
                
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                2.13
                
                    
                        org.apache.maven.surefire
                        surefire-junit47
                        2.13
                    
                
                
                    ${testcase.groups}
                
            
        
    

(4) In my project, by default all 7 test methods will be executed during Maven build:

Java中@Category注解的工作原理是什么

Suppose you only want to execute unit test belonging to category “SlowTests”, use the following command line:

Java中@Category注解的工作原理是什么

Since now I only marked one method with annotation SlowTests, only one test method is executed:

Java中@Category注解的工作原理是什么

If you would like to execute all unit tests EXCEPT @SlowTests, simply add another profile in pom.xml:


            NonSlowTests
            
                
                    
                        org.apache.maven.plugins
                        maven-surefire-plugin
                        
                            com.sap.SlowTests
                        
                    
                
            
        

Before test, in order to prove that Slow method is NOT really executed, I add a system.out.println in each method:

Java中@Category注解的工作原理是什么

Use command line: mvn test -P NonSlowTests From console output, I can ensure that the method with @Category(SlowTests.class) is NOT executed at all.

Java中@Category注解的工作原理是什么

看完上述内容,你们对Java中@Category注解的工作原理是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联-成都网站建设公司行业资讯频道,感谢大家的支持。


当前名称:Java中@Category注解的工作原理是什么-创新互联
文章地址:http://www.cdkjz.cn/article/dcoocj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220