【问题标题】:Failed TestNG tests with DataProvider in IntelliJ IDEA在 IntelliJ IDEA 中使用 DataProvider 进行的 TestNG 测试失败
【发布时间】:2014-11-24 20:19:02
【问题描述】:

我最近开始玩 tdd 并遇到了一个问题,我不明白为什么一件事有效而另一件事不工作。

以下代码适用于我:

public class Ant {

    public Ant(Point startLocation, Point hive) {
        this.currentLocation = new Point(startLocation);
        this.hive = new Point(hive);
    }

    public void goHome() {
        if (hive.x > currentLocation.x) {
            currentLocation.x++;
        } else if (hive.x < currentLocation.x){
            currentLocation.x--;
        }
        if (hive.y > currentLocation.y) {
            currentLocation.y++;
        } else if (hive.y < currentLocation.y){
            currentLocation.y--;
        }
    }
}

对应的测试:

@DataProvider(name = "goneHome")
public static Object[][] goHome() {
    return new Object[][] {
            {new Point(2,1), new Point(3,2), new Point(7,8)},
            {new Point(20,1), new Point(19,2), new Point(7,8)},
            {new Point(23,10), new Point(22,9), new Point(7,8)},
            {new Point(2,10), new Point(3,9), new Point(7,8)},
            {new Point(2,8), new Point(3,8), new Point(7,8)},
            {new Point(7,1), new Point(7,2), new Point(7,8)}
    };
}

@Test(dataProvider = "goneHome")
public void testGoHome(Point currentPosition, Point nextPosition, Point hive) 
    throws Exception {
    Ant ant = new Ant(currentPosition, hive);

    ant.move();
    assertEquals(ant.getCurrentLocation(), nextPosition);
}

如果我像这样更改 ant 构造函数,则测试失败:

public Ant(Point startLocation, Point hive) {
    this.currentLocation = startLocation;
    this.hive = hive;
}

失败是指前两组 DataProvider 的测试工作正常,其余的失败/未完成。 虽然我不太确定是什么失败了。如果我删除 DataProvider 中的前两组数据,仍然只有前两个数据集(之前的第 3 和第 4 个数据集)不会失败。

我使用IntelliJ,除了“失败”测试的符号仍然是“加载图标”。

调试每个单独的测试用例表明点设置正确。从测试中删除断言不会改变任何东西。

有人可以向我解释一下这种行为吗?

提前致谢

埃贡

编辑:更正了失败的构造函数版本

【问题讨论】:

  • 您是否尝试将测试作为 Maven 目标运行?也许这是 Idea 中的一个错误
  • 它适用于 maven,谢谢!我花了太长时间思考这个^^
  • 即使是最聪明的工具也会失败

标签: java intellij-idea testng parameterized-unit-test


【解决方案1】:

也许这是 IntelliJ IDEA 中的一个错误。有时我也面临这个问题。不幸的是它仍然(2014-11-24)未解决:https://youtrack.jetbrains.com/issue/IDEA-100752

尝试使用备用运行器运行您的测试(例如,作为 Maven 目标)。

【讨论】:

  • 它适用于 maven,谢谢!我花了太长时间思考这个问题,对不起,我不能放弃你,因为我是 stackoverflow 的新手
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-15
  • 2016-04-26
  • 2016-11-20
  • 2011-08-04
相关资源
最近更新 更多