详细信息

建议类型:额外的线程

是否可在首选项配置:是

过滤器分类:不稳定的测试环境

说明

避免编写有副作用的测试用例。额外的线程可能会改变系统状态,导致随机测试失败。

示例

@Test
public void testChangeState() throws Exception {
    new Thread(new Runnable() {

        public void run() {
            System.out.println("foo");
        }

    }).start();

    State initialState = new State("state", 2);
    // Given
    TrackableMethodExample underTest = new TrackableMethodExample(initialState);

    // When
    State newState = new State("state changed", 10);
    ResultStatus result = underTest.changeState(newState);

    Assert.assertNotNull(result);
}