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:
(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 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:
Suppose you only want to execute unit test belonging to category “SlowTests”, use the following command line:
Since now I only marked one method with annotation SlowTests, only one test method is executed:
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:
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注解的工作原理是什么-创新互联
文章路径:http://pwwzsj.com/article/dcoocj.html