无根测试 [英] Unrooted Tests

查看:21
本文介绍了无根测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Eclipse(Eclipse 3.4 'Ganymede')中运行我的所有测试时,一个测试列在Unrooted Tests"下.我正在使用 Junit 3.8,这个特定的测试扩展了 TestCase.我看不出这个测试和其他测试有什么区别.我不记得在 Eclipse 3.3(欧洲)中看到过这种情况.

When running all my tests in Eclipse (Eclipse 3.4 'Ganymede'), one test is listed under "Unrooted Tests". I'm using Junit 3.8 and this particular test extends TestCase. I do not see any difference between this test and the other tests. I don't remember seeing this occur in Eclipse 3.3 (Europa).

澄清:

我们还没有迁移到 JUnit 4.0,所以我们没有使用注解.我也用谷歌搜索过,似乎大多数人都遇到了 JUnit 4 的问题,但我没有看到任何解决方案.在这一点上,本地和 CruiseControl 中的测试都通过了,所以我并不过分担心,但很好奇.

We haven't moved to JUnit 4.0 yet, so we are not using annotations. I also googled and it seemed like most people were having issues with JUnit 4, but I did not see any solutions. At this point the test passes both locally and in CruiseControl so I'm not overly concerned, but curious.

当我第一次看到这个时,它是在一个失败的测试中,只有在与其他测试一起运行时才会失败.这让我陷入了困境,寻找我从未找到的无根"问题的解决方案.最终,我在另一个没有正确拆卸的测试中找到了罪魁祸首.

When I first saw this, though, it was on a failing test that only failed when run with other tests. This led me down the rabbit hole looking for a solution to the "Unrooted" issue that I never found. Eventually I found the culprit in another test that was not properly tearing down.

我同意,这似乎是 Eclipse 问题.

I agree, it does seem like an Eclipse issue.

推荐答案

我终于找到了解决方案.问题是您没有使用注释定义测试用例,但仍在以旧方式"进行操作.一旦您转换为使用注释,您就可以一次再次运行一个测试.

Finally I found the solution. The problem is that you are not defining your test cases using annotations but are still doing it the "old way". As soon as you convert over to using annotations you will be able to run one test at a time again.

以下是使用注释的基本测试现在应该是什么样子的示例:

Here is an example of what a basic test should now look like using annotations:

import static org.junit.Assert.*; // Notice the use of "static" here
import org.junit.Before;
import org.junit.Test;

public class MyTests { // Notice we don't extent TestCases anymore

  @Before
  public void setUp() { // Note: It is not required to call this setUp()
    // ...
  }

  @Test
  public void doSomeTest() { // Note: method need not be called "testXXX"
    // ...
    assertTrue(1 == 1);
  }
}

这篇关于无根测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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