简体   繁体   English

如何配置JUnit测试套件?

[英]How to configure JUnit test suite?

I have a Java project which has layered structure. 我有一个具有分层结构的Java项目。 And each time when commit is made Hudson build is running with all test cases to make sure that code is not broken by new changes. 每次提交时, Hudson构建都会运行所有测试用例,以确保代码不会被新的更改破坏。 But this may take considerable amount of time due to running test cases for persistence (Hibernate) layer. 但是由于运行持久性(Hibernate)层的测试用例,这可能需要相当长的时间。 Also there is a Sonar build which runs each night. 每天晚上还有一个Sonar版本。

Now I am looking for a way of optimizing test running. 现在我正在寻找一种优化测试运行的方法。 I want to remove persistence layers tests from Hudson build and only run it in Sonar. 我想从Hudson构建中删除持久层测试,只在Sonar中运行它。 Now it should have two different test suites (profiles). 现在它应该有两个不同的测试套件(配置文件)。

Any suggestion very much appreciated. 任何建议非常感谢。

Seems like you are looking to use JUnit Categories - https://weblogs.java.net/blog/johnsmart/archive/2010/04/25/grouping-tests-using-junit-categories-0 好像你正在寻找使用JUnit类别 - https://weblogs.java.net/blog/johnsmart/archive/2010/04/25/grouping-tests-using-junit-categories-0

You can then configure your build server to run specific categories at different times 然后,您可以将构建服务器配置为在不同时间运行特定类别

More info here - https://github.com/junit-team/junit/wiki/Categories 更多信息在这里 - https://github.com/junit-team/junit/wiki/Categories

If you are using Junit 4.8 or higher you can use JUnit Categories to separate your tests and run only tests that are in certain categories. 如果您使用的是Junit 4.8或更高版本,则可以使用JUnit Categories来分隔测试并仅运行某些类别的测试。

See these links for more information: 有关更多信息,请参阅以下链接

JUnit Categories JavaDoc JUnit类别JavaDoc

Blog tutorial 博客教程

How to run categories in Maven (scroll down some until the "Using JUnit Categories" section) 如何在Maven中运行类别(向下滚动一些直到“使用JUnit类别”部分)

I think you want to separate into 2 test phases: 我想你想分成两个测试阶段:

  • unit, for the fast-running tests 单元,用于快速运行的测试
  • integration, for the Hibernate-style slower ones. 集成,适用于Hibernate风格较慢的。

Unit tests are run by Surefire plugin, with integration ones run by Failsafe 单元测试由Surefire插件运行,集成测试由Failsafe运行

These run in a different phases of the maven standard build lifecycle, so you can set the integration tests to only run on your SONAR build. 它们运行在maven标准构建生命周期的不同阶段,因此您可以将集成测试设置为仅在SONAR构建上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM