【问题标题】:How to test individual testng methods when it depends on other methods当依赖于其他方法时如何测试单个测试方法
【发布时间】:2014-06-25 22:35:54
【问题描述】:

考虑以下示例代码

public class PropertyServiceTest extends AbstractTestNGSpringContextTests {
  @Test(groups={"property_service"})
  public void testCreateProperty() { ... }

  @Test(groups={"property_service"}, dependsOnMethods={"testCreateProperty"})
  public void testCreateProperty1() {...P
}

当我使用 maven 执行单个测试“testCreateProperty1”时,

mvn -Dtest=PropertyServiceTest#testCreateProperty1 出现以下异常。

原因:org.testng.TestNGException: com.service.PropertyServiceTest.testCreateProperty1() 依赖于方法 public void com.service.PropertyServiceTest.testCreateProperty(),没有用@Test 注释

at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:95)
at org.testng.internal.MethodHelper.topologicalSort(MethodHelper.java:245)
at org.testng.internal.MethodHelper.sortMethods(MethodHelper.java:316)
at org.testng.internal.MethodHelper.collectAndOrderMethods(MethodHelper.java:51)

请帮我解决这个问题。

【问题讨论】:

  • 出于好奇,您是否尝试过将您的@Test 方法设为public
  • 所有方法都是公开的。我也编辑了 qn。

标签: junit testng spring-test


【解决方案1】:

这似乎与 Spring TestContext Framework 无关。

相反,这似乎是 TestNG 的配置问题。

因此,您可能会发现 Google 网上论坛上的“How to solve test method dependencies?”讨论很有帮助。

如果这能帮助您解决问题,请告诉我们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-29
    • 2023-04-10
    相关资源
    最近更新 更多