【发布时间】:2016-01-22 21:16:09
【问题描述】:
我试图找出当我尝试运行一些已创建并在一段时间前运行过的测试时出现错误的原因。这是测试类:
package com.chw.pxi.impl.oneway.formatter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
public class OnewayOldFormatterTestsWhy
{
@Before
public void setUp()
{
}
@Test
public void
test_nothing()
{
System.out.println("Yep");
}
}
这是我尝试通过右键单击运行“test_nothing”方法时出现的错误,选择“Run As/Junit test”。
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test_nothing], {ExactMatcher:fDisplayName=test_nothing(com.chw.pxi.impl.oneway.formatter.OnewayOldFormatterTestsWhy)], {LeadingIdentifierMatcher:fClassName=com.chw.pxi.impl.oneway.formatter.OnewayOldFormatterTestsWhy,fLeadingIdentifier=test_nothing]] from org.junit.internal.requests.ClassRequest@3632be31
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
此项目的构建路径中有很多 jar 文件。我想我应该尝试创建一个新项目,看看问题是否随之而来。附注 - 当我在另一个具有此功能的测试中对方法运行测试时 - 它运行良好,没有上述错误:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"dao-tests-context.xml"})
@TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true)
//Note: This is a live database test but transactions will be rolled back
//except those that invoke methods that require new transactions
public class AgencyDaoTests
如果需要其他信息,请让我知道我可以做什么以及如何为您获取这些信息。
谢谢,迈克尔
【问题讨论】:
-
您是否尝试使用其他类名?例如:OnewayOldFormatterTest
-
上面的方法是一个大型的 Junit 测试,之前可以运行,我创建了它。起初我对您的建议不太清楚,但将课程重命名为另一个名称。结果相同。我什至尝试过其他具有相同结果的测试类。我已经对这个问题进行了很多搜索,并且已经完成了所有建议但没有结果。它一定是我的电脑的问题,因为我的同事能够毫无问题地运行。
-
我想说
PowerMockRunner试图找到所有 PowerMock 值以用它自己的实现替换它们。看来您没有设置任何内容。尝试添加一个@PrepareForTest注释,其中至少包含一个类,以便跑步者可以选择它......