我開始使用java maven項目,我對此很陌生。我使用了Spring註釋,當我運行我的測試類時,它給出了以下錯誤。java中的maven項目中的initializationError(org.junit.runner.manipulation.Filter)
FirstTryTest.testFirst initializationError(org.junit.runner.manipulation.Filter) java.lang.Exception的:未找到匹配的測試 [{ExactMatcher:fDisplayName = testFirst], {ExactMatcher:fDisplayName = testFirst (com.mycompany.test.FirstTryTest)], {LeadingIdentifierMatcher:fClassName = com.mycompany.test.FirstTryTest,fLeadingIdentifier = testFirst]] [email protected] org.junit.internal .requests.FilterRequest.getRunner(FilterRequest.java:40) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.crea teFilteredTest(JUnit4TestLoader.java:77)在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests (JUnit4TestLoader.java:43) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:678) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (RemoteTestRunner.java:192)
我的測試類看起來像這樣。
package com.mycompany.test;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import com.mycompany.config.AppConfig;
import com.mycompany.service.FirstTryService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { AppConfig.class }, loader = AnnotationConfigContextLoader.class)
public class FirstTryTest {
@Autowired
private FirstTryService firstTryService;
@Test
public void testFirst() {
Integer rCal = firstTryService.cal(10, 10);
Assert.assertNotNull(rCal);
// System.out.println(rCal);
}
@Test
public void testSecond() {
System.out.println("hello world");
}
}
以下是我的服務和服務impl文件。
package com.mycompany.service;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public interface FirstTryService {
Integer cal(Integer x, Integer y);
}
package com.mycompany.serviceImpl;
import org.springframework.stereotype.Service;
import com.mycompany.service.FirstTryService;
@Service
public class FirstTryServiceImpl implements FirstTryService {
@Override
public Integer cal(Integer x, Integer y) {
Integer calPlus = x + y;
return calPlus;
}
}
如何解決此錯誤?