在测试类中找不到PowerMock投掷类例外



我正在使用powermock with ant build and spring 3.0。当我使用SpringJunit4ClassRunner注释时,测试运行良好。但是,当我用PowerMockRunnerDelegate实现PowermockRunner(1.6.5)时,跑步者无法检测到测试类本身。

@Named("teskListTest")
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:conf/TestBeans.xml"})
@PrepareForTest(SysList.class)
public class SysListTest {  
SysList sysList;
@Test
public void addSysWithIdTest() throws Exception {
    System.out.println("SysListTest : Entering addSysWithIdTest ");
    java.util.logging.Logger log = Mockito.mock(java.util.logging.Logger.class);
    sysList = new SysList(log);
    Component comp = Mockito.mock(Component.class);
    PowerMockito.whenNew(Component.class).withNoArguments().thenReturn(comp);
    sysList.test();
    Mockito.verify(comp).getId();
    System.out.println("sysListTest : Exiting addsysWithIdTest");
}

我得到的例外是:

[junit] Running com.example.unittest.SystemTestSuite
[junit] Testsuite: com.example.unittest.SystemTestSuite
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.02 sec
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.02 sec
[junit]
[junit] Testcase: initializationError took 0.002 sec
[junit]     Caused an ERROR
[junit] com.example.tasktest.SysListTest
[junit] java.lang.ClassNotFoundException: com.example.tasktest.SysListTest
[junit]     at java.lang.Class.forName(Class.java:219)
[junit]     at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:161)
[junit]     at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:48)
[junit]     at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:113)
[junit]     at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:71)
[junit]     at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
[junit]     at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
[junit]     at java.lang.reflect.Constructor.newInstance(Constructor.java:539)
[junit]     at java.lang.reflect.Constructor.newInstance(Constructor.java:539)
[junit]     at java.lang.reflect.Constructor.newInstance(Constructor.java:539)
[junit]
[junit] Test com.example.unittest.TaskTestSuite FAILED

我尝试使用Mockito 1.9.5,1.10.16。尝试使用1.6.1和1.6.5版本的PowerMock Jar和Junit 4.12,4.11。例外从未改变。

看起来您的生产课程不是测试类路径的一部分。我认为问题是您的build.xml。请看一下Junit的"入门 - 蚂蚁"文章。

相关内容

  • 没有找到相关文章

最新更新