简体   繁体   English

在JUnit测试类中运行基准测试方法

[英]Running benchmark methods in a JUnit test class

I have a test class MyTestClass with several typical test methods that do assertions or check for exceptions and are annotated with @Test . 我有一个带有几个典型测试方法的测试类MyTestClass ,这些方法可以进行断言或检查异常,并使用@Test进行注释。 They run when I call the following directive in an Ant task: 它们在我在Ant任务中调用以下指令时运行:

<test name="MyTestClass"/>

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. 我希望有一个完全独立的Ant任务来运行这些基准测试。

Is there an annotated way to introduce this classification of tests and invoke each category separately? 有没有注释的方法介绍这种测试分类并分别调用每个类别? Eg 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. 例如,带@Test注释的方法将是第一类,然后虚构的@Benchmark方法将只是记录性能指标以进行诊断报告,而不是进行断言或断言。 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. 我认为测试类是放置这些基准测试方法的最佳方法,但是我不知道如何将它们的调用封装在Ant中,以便它们分别运行。 Eg, 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? 例如,是否可以给每个方法加上“基准”作为前缀,并告诉Ant仅运行以该方法为前缀的方法,或者我可以编写自己的注释?

I think you probably want to look at JUnit Categories . 我认为您可能想看看JUnit Categories There are other answers that detail how to execute specific categories from ant. 还有其他答案,详细说明了如何从ant执行特定类别。

How to run all JUnit tests in a category/suite with Ant? 如何使用Ant在类别/套件中运行所有JUnit测试?
How to run all tests belonging to a certain Category in JUnit 4 如何在JUnit 4中运行属于某个类别的所有测试

Some external links that may be of use: 可能有用的一些外部链接:
Grouping tests using JUnit categories 使用JUnit类别对测试进行分组
A Closer Look at JUnit Categories 仔细研究JUnit类别

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

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