使用 JUnit 的 @Parameterized 时,我可以让一些测试仍然只运行一次吗 [英] When using JUnit's @Parameterized, can I have some tests still run only once

查看:27
本文介绍了使用 JUnit 的 @Parameterized 时,我可以让一些测试仍然只运行一次吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在许多情况下使用 @Parameterized 来对许多排列运行测试.这非常有效,并且使测试代码本身保持简单和干净.

I use @Parameterized in many cases to run tests on a number of permutations. This works very well and keeps the test-code itself simple and clean.

但是有时我希望某些测试方法仍然只运行一次,因为它们不使用参数,JUnit 有没有办法将测试方法标记为单例"或运行-一次"?

However sometimes I would like to have some of the test-methods still run only once as they do not make use of the parameters, is there a way with JUnit to mark the test-method as "singleton" or "run-once"?

注意:这与在 Eclipse 中运行单个测试无关,我知道该怎么做 :)

Note: This does not concern running single tests in Eclipse, I know how to do that :)

推荐答案

您可以将任意数量的测试类关联起来使用套件一起运行.这样,当您测试类时,所有测试都会运行,并且您可以混合不同的测试运行器.

You can associate any number of test classes to run together using a suite. This way all the tests are run when you test your class and you can mix different test runners.

  1. 创建与您正在测试的类相关联的测试套件
  2. 添加对参数化测试类的引用
  3. 添加包含非参数化测试的其他类.

  1. Create a test suite associated with the class you are testing
  2. Add a reference to the parameterized test class
  3. Add the other class(es) containing non parameterized tests.

import org.junit.runners.Suite;
import org.junit.runner.RunWith;

@RunWith(Suite.class)
@Suite.SuiteClasses({ParameterizedTestClass.class, UnitTests.class, MoreUnitTests.class})
public class SutTestSuite{
     //Empty...
}

这篇关于使用 JUnit 的 @Parameterized 时,我可以让一些测试仍然只运行一次吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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