用于将类标记为测试类的任何注释?

时间:2017-07-21 15:22:25

标签: java junit junit4

我是Junit4的新手,我想知道是否有一些注释将类标记为测试类就像使用

一样

@Test将方法标记为测试方法。

2 个答案:

答案 0 :(得分:0)

您可以在班级使用# config/environments/test.rb # Use webpack dev server when running tests locally unless ENV["TDDIUM"].present? ENV["NODE_ENV"] = "development" end 注释,例如:

@Category

我在https://www.mkyong.com/unittest/junit-categories-test/

中引用了这个例子

此外,如果您运行Spring测试,使用JUnit进行Mockito测试,那么您必须在类级别使用@Category({PerformanceTests.class, RegressionTests.class}) public class ClassB { @Test public void test_b_1() { assertThat(1 == 1, is(true)); } } 注释。

例如在Spring启动测试中我使用它:

@RunWith

在Mockito(没有弹簧测试)测试我用过:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
public class ControllerTest {

答案 1 :(得分:0)

注释 @TestOnly,但它确实带有警告,如下所示。

import org.jetbrains.annotations.TestOnly;

警告

/**
 * A member or type annotated with TestOnly claims that it should be used from testing code only.
 * <p>
 * Apart from documentation purposes this annotation is intended to be used by static analysis tools
 * to validate against element contract violations.
 * <p>
 * This annotation means that the annotated element exposes internal data and breaks encapsulation 
 * of the containing class; the annotation won't prevent its use from production code, developers 
 * won't even see warnings if their IDE doesn't support the annotation. It's better to provide 
 * proper API which can be used in production as well as in tests.
 */

解决方法

如果有我专门用于测试的代码体或类需要在发布时删除它们,我会使用 Android Studio 添加自定义 TODO(不确定其他 IDE 是否具有相同的功能),请按照下面的屏幕截图和底部的 TODO 选项卡中,您将在左侧看到每个自定义 TODO 的过滤器。这绝不是最好的方法,但我发现这是在发布时删除代码最快的手动方法。

Custom TODO in Android Studio

TODO Filter

P.S 我知道这张截图中的模式很混乱。

相关问题