本文介绍了在运行JUnit测试类的基准方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试类 MyTestClass 有几种典型的测试方法是做断言或检查异常和 @Test 。它们在运行时我叫下面的指令在Ant任务:

I have a test class MyTestClass with several typical test methods that do assertions or check for exceptions and are annotated with @Test. They run when I call the following directive in an Ant task:

<试验NAME =MyTestClass/>

然而,在同一类我想位于未包括在必须通过测试几个基准性能的方法。我想有运行这些基准测试一个完全独立的Ant任务。

However, in the same class I would like to situate several benchmark performance methods that are not included in the tests that must be passed. I would like to have an altogether separate Ant task that runs these benchmarking tests.

有每个类别分别介绍了测试这种分类和调用方式注释?例如。在 @Test 注解的方法将是1类,然后虚构 @Benchmark 方法就简单地记录诊断性能指标报告,这样做的断言被创造或打破。我想测试类是位于这些基准测试方法的最佳方式,但我不知道如何封装它们的调用Ant中,使他们单独运行。例如,是否有可能以preFIX用标杆每一种方法,并告诉Ant来运行只有那些与pfixed $ P $或者我可以写我自己的注释?方法

Is there an annotated way to introduce this classification of tests and invoke each category separately? E.g. the @Test annotated methods would be 1st class and then the fictitious @Benchmark methods would simply be logging performance metrics for diagnostics reporting, not do assertions that are make or break. I think the test class is the best way to situate these benchmarking methods, yet I don't know how to encapsulate their invocation in Ant so that they are run separately. E.g., is it possible to prefix each method with "benchmark" and tell Ant to run only methods that are prefixed with that or can I write my own annotation?

推荐答案

我想你也许想看看的JUnit的的。还有其他的答案,详细说明了如何从蚂蚁执行特定类别。

I think you probably want to look at JUnit Categories. There are other answers that detail how to execute specific categories from ant.

How与蚂蚁运行在一个类别/套件中的所有JUnit测试?结果
How运行属于某一类别的所有测试JUnit 4中

一些外部链接,可能是有用的:结果
分组使用JUnit类结果测试

Some external links that may be of use:
Grouping tests using JUnit categories
A Closer Look at JUnit Categories

这篇关于在运行JUnit测试类的基准方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 19:11