我在 grails 2.0.3 中为服务创建了一个单元测试,我想在 eclipse 中使用 junit runner 运行这个测试。当我右键单击 test-class => debug as => junit test 我在控制台中收到以下错误消息:
Class not found myProject.ReportServiceTests
java.lang.ClassNotFoundException: myProject.ReportServiceTests
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:693)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:429)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
我在 test/unit/myProject 中的 ReportServiceTest.groovy:
package myProject
import grails.test.mixin.*
import grails.test.mixin.support.*
import org.junit.*
/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(myProject.ReportService)
@Mock(Sale)
class ReportServiceTests {
void setUp() {
// Setup logic here
}
void tearDown() {
// Tear down logic here
}
void testSomething() {
fail "Implement me"
}
void testGetSalesCompleted() {
def salesCompleted = service.getSalesCompleted()
if(salesCompleted.count > 0) {
assertTrue()
}
fail "no sales completed"
}
}
错误在哪里?预生成的 *ControllerTests.groovy 在 Eclipse 中与 junit runner 一起工作正常!我正在使用 STS:SpringSource 工具套件
版本:2.9.2.RELEASE 构建 ID:201205071000