Ant 可以根据继承层次结构对 JUnit 测试进行分类吗? [英] Can Ant categorise JUnit tests based on inheritance hierarchy?

查看:30
本文介绍了Ant 可以根据继承层次结构对 JUnit 测试进行分类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个具有以下特性的遗留项目:

I'm working with a legacy project that has:

  • 纯单元测试
  • 集成测试(运行缓慢;有各种讨厌的依赖项)

我正在寻找最简单的方法来单独使用 Ant 运行这两种类型的测试.

I'm looking for the simplest way to run both types of tests separately with Ant.

我想知道是否有办法让 Ant 根据继承层次结构自动识别这两个类别:

I wonder if there's a way to have Ant automatically recognise these two categories based on the inheritance hierarchy:

StringUtilsTest extends TestCase  // "pure unit test"

对比

ProductionDBTest extends AbstractTransactionalTesterBase // "integration test"

集成测试基于抽象超类的层次结构,但它们都归结为一些 Spring 测试类和最终的 AbstractSpringContextTests,它扩展了 junit.framework.TestCase.

There's a hierarchy of abstract superclasses that integration tests are based on, but they all come down to some Spring test classes and ultimately AbstractSpringContextTests which extends junit.framework.TestCase.

换句话说,我能否在 Ant 中区分(间接)扩展 AbstractSpringContextTests 的测试和直接扩展 TestCase 的测试?或者我是否必须手动通过测试,例如将它们放在单独的类别或测试套件中?(有很多测试,所以我不想这样做.)

In other words, can I distinguish, in Ant, tests that (indirectly) extend AbstractSpringContextTests and tests that directly extend TestCase? Or would I have to manually go through the tests and e.g. put them in separate Categories or TestSuites? (There are many tests so I wouldn't want to do that.)

解决方案:我尝试了 Sean 的(非常有前途)方法,但无法使其工作(很容易).所以我最终以半手动方式完成了测试,使用 this SO question,并使用 Ant 像这样.(请注意,编写自定义 TestRunner 不是 必要的.)

Resolution: I tried Sean's (very promising) approach, but couldn't get it working (easily). So I ended up going through the tests semi-manually after all, annotating the pure ones (which was the smaller group) using a setup described in this SO question, and running them with Ant like this. (Note that writing a custom TestRunner is not necessary.)

推荐答案

我们用于对 JUnit 测试进行分类的解决方案是使用自定义注释.然后,您可以使用自定义的 TestRunner,它可以被赋予一个标志或参数来确定要运行的测试类型或所有测试类型.

The solution we used for categorizing our JUnit tests was using a custom annotation. You can then use a custom TestRunner with that which can be given a flag or argument as to which test types to run, or all of them.

抱歉,没有示例代码,但创建注释和 TestRunner 是非常基本的,试一试!

Sorry, no example code but creating annotations and a TestRunner is pretty basic, give it a try!

这篇关于Ant 可以根据继承层次结构对 JUnit 测试进行分类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆