JavaMaven项目中的初始化错误(org.junit.runner.manipulation.Filter)

JavaMaven项目中的初始化错误(org.junit.runner.manipulation.Filter),java,spring,maven,annotations,Java,Spring,Maven,Annotations,我刚开始从事JavaMaven项目,对此我是新手。我使用了spring注释,当我运行我的测试类时,它给出了以下错误 FirstTryTest.testFirst 初始化错误(org.junit.runner.manipulation.Filter) java.lang.Exception:未找到匹配的测试 [{ExactMatcher:fDisplayName=testFirst], {ExactMatcher:fDisplayName=testFirst(com.mycompany.test.

我刚开始从事JavaMaven项目,对此我是新手。我使用了spring注释,当我运行我的测试类时,它给出了以下错误

FirstTryTest.testFirst 初始化错误(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]] 来自org.junit.internal.requests。ClassRequest@7b0070在 org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(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;
    }

}

如何修复此错误?

我刚收到与您发布的错误相同的错误。然后我发现此错误是由测试函数中不必要的输入参数引起的。我不能告诉您有相同的原因。但您可以使用我的步骤来获取错误的详细信息(这似乎是eclipse的一个错误,至少它应该在这个主题上有所增强)

在eclipse中,不要单独选择要测试的测试函数,而要在“测试”选项卡上选择“运行所选项目中的所有测试”选项,在单击“运行->运行(调试)配置”后选择Junit项目名称

你可以参考我的答案: