控制 Ant 运行哪些 JUnit 测试
我有一个像这样设置的 ant 任务:
<target name="unit-test" description="unit tests" depends="compile-tests">
<mkdir dir="${build}/test"/>
<mkdir dir="${build}/test/raw"/>
<mkdir dir="${build}/test/reports"/>
<!-- set up scratch database for tests -->
<mkdir dir="${build.dbTest}" />
<junit printsummary="yes" haltonfailure="no" maxmemory="512m" >
<classpath>
<pathelement path="${java.class.path}"/>
<pathelement path="${build.classes}"/>
<pathelement path="${build.test-classes}"/>
<fileset dir="lib" includes="*.jar"/>
<fileset dir="lib-test" includes="*.jar"/>
</classpath>
<formatter type="xml"/>
<sysproperty key="derby.system.home" value="${build.dbTest}" />
<batchtest fork="yes" todir="${build}/test/raw">
<fileset dir="${src.test}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${build}/test">
<fileset dir="${build}/test/raw"/>
<report todir="${build}/test/reports"/>
</junitreport>
</target>
这对于运行我的所有测试非常有效,但是运行我的所有测试确实减慢了我的 TDD 失败-通过-重构节奏。我的完整测试套件需要大约六分钟才能运行,这对于 TDD 期间的快速响应更改来说太长了,特别是因为大多数时候我只关心一项测试的结果。我想要的工作流程是
- 为新功能/错误创建测试
- 仅运行新测试(或最多仅运行我刚刚修改的测试类)
- 编写一些代码
- 迭代2-3,直到新测试通过
- 运行完整一组测试,以确保没有其他问题
- 将任何损坏的测试插入上面的 2-3 个循环中,并
- 在所有测试通过后重复整个循环,宣布胜利。
TestNG 似乎具有对测试进行分组的功能,这似乎是理想的(我可以为我当前正在使用的测试创建一个“TDD”组。当我开始处理某件事时更改它是这里可接受的手动配置级别),但是除非绝对必要,否则我不想切换测试框架。有没有什么方法可以使用 JUnit 做类似的事情,或者有其他方法来实现我想要的工作流程?
I have an ant task set up like so:
<target name="unit-test" description="unit tests" depends="compile-tests">
<mkdir dir="${build}/test"/>
<mkdir dir="${build}/test/raw"/>
<mkdir dir="${build}/test/reports"/>
<!-- set up scratch database for tests -->
<mkdir dir="${build.dbTest}" />
<junit printsummary="yes" haltonfailure="no" maxmemory="512m" >
<classpath>
<pathelement path="${java.class.path}"/>
<pathelement path="${build.classes}"/>
<pathelement path="${build.test-classes}"/>
<fileset dir="lib" includes="*.jar"/>
<fileset dir="lib-test" includes="*.jar"/>
</classpath>
<formatter type="xml"/>
<sysproperty key="derby.system.home" value="${build.dbTest}" />
<batchtest fork="yes" todir="${build}/test/raw">
<fileset dir="${src.test}">
<include name="**/*Test.java"/>
</fileset>
</batchtest>
</junit>
<junitreport todir="${build}/test">
<fileset dir="${build}/test/raw"/>
<report todir="${build}/test/reports"/>
</junitreport>
</target>
Which works pretty well for running all my tests, but running all my tests really slows down my TDD Fail-Pass-Refactor groove. My full test suite takes about six minutes to run, which is way too long for quick response changes during TDD, especially since most of the time I only care about results from one test. The work flow I'd like to have would be
- create test for new feature/bug
- run only the new test (or at most only the test class I just modified)
- write some code
- iterate 2-3 until the new tests are passing
- run full set of tests to make sure nothing else broke
- plug any broken test into the 2-3 cycle above and repeat full cycle
- when all tests pass, declare victory.
TestNG seems to have capability for grouping tests, which seems ideal (I could have a "TDD" group for the tests I'm currently working with. Changing that when I start working on something is an acceptable level of manual configuration here), but I don't want to switch test frameworks unless I absolutely have to. Is there any way to do something similar, or another way to achieve my desired work flow, using JUnit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在脚本中使用而不是
代码片段
,并将属性测试设置为脚本前面的
**/*Test.java
。现在我可以启动 ant,将属性设置为不同的值:I use in my scripts instead of
the snippet
and set the property test to
**/*Test.java
earlier in the script. Now I can start ant, setting the property to a different value: