PowerMockRunner在委派给HierarchicalContextRunner时无法从描述中确定方法名称

时间:2019-03-25 10:05:38

标签: junit powermock test-runner

我正在尝试将PowerMockRunner与HierarchicalContextRunner结合使用,但是在“嵌套”测试结束后出现错误

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(HierarchicalContextRunner.class)
@SuppressStaticInitializationFor({
    "my.old.legacy.manager.LegacyManager"
})
@PrepareForTest({
    SomeOtherLegacyClasseToSuppress.class
})
public class MyComponentTest {

    @Test
    public void simpleTest() {
     ...
    }

    public class WhenCondition {

        @Test
        public void serviceShouldDoSomething() {
         ...
        }
    }
}

simpleTest似乎运行正常,但是serviceShouldDoSomething测试返回以下消息:

java.lang.IllegalArgumentException: Unable to determine method-name from description=serviceShouldDoSomething(...MyComponentTest$WhenCondition); - ignored

这是我有效的pom:

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>de.bechte.junit</groupId>
      <artifactId>junit-hierarchicalcontextrunner</artifactId>
      <version>4.12.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.hamcrest</groupId>
      <artifactId>hamcrest-all</artifactId>
      <version>1.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-api-mockito2</artifactId>
      <version>2.0.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.powermock</groupId>
      <artifactId>powermock-module-junit4</artifactId>
      <version>2.0.0</version>
      <scope>test</scope>
    </dependency>

0 个答案:

没有答案