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

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

网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、成都小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了丹徒免费建站欢迎大家使用!

(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://bzwzjz.com/article/pogics.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站建设 高端网站设计 网站制作报价 手机网站制作 成都网站建设 成都网站设计 成都响应式网站建设 成都定制网站建设 高端品牌网站建设 重庆网站建设 定制网站建设多少钱 泸州网站建设 网站建设 成都网站建设公司 成都做网站建设公司 成都网站制作 成都网站建设 达州网站设计 专业网站设计 网站建设方案 响应式网站设计 网站制作