网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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://bjjierui.cn/article/pogics.html

其他资讯