今天就跟大家聊聊有关Java中@Category注解的工作原理是什么,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、成都小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了丹徒免费建站欢迎大家使用!
(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注解的工作原理是什么有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。