SpringJUnit4ClassRunner with JUnit testuite error

I am trying to install the Junit test suite with Spring for the first time and tried with a couple of changes in my classes, but no luck and ended up with this error: "junit.framework.AssertionFailedError: no tests found in Myclass"

In short, I have two test classes, both from the same base class, which loads the Spring context below

@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations =
{
"classpath:ApplicationContext.xml"
})

I tried adding these 2 test classes to the set as shown below

@RunWith( SpringJUnit4ClassRunner.class )
@SuiteClasses({ OneTest.class, TwoTest.class })
public class MyTestSuite extends TestCase {

//nothing here
}

I run this test suite from ant. But, it gives me an error saying: โ€œNo tests foundโ€ However, if I run the separate 2 test cases from ant, they work correctly. Not sure why this behavior, I'm sure something is missing here. Please advice.

+5
source share
1

, TestSuite @RunWith(Suite.class) @SuiteClasses({}). @RunWith(SpringJunit4ClassRunner.class) @ContextConfiguration(locations = {classpath:META-INF/spring.xml}) , AbstractTestCase , , . :

/**
 * An abstract test case with spring runner configuration, used by all test cases.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations =
{ "classpath:META-INF/spring.xml" })
public abstract class AbstractSampleTestCase
{
}


public class SampleTestOne extends AbstractSampleTestCase
{
    @Resource
    private SampleInterface sampleInterface;

    @Test
    public void test()
    {
        assertNotNull(sampleInterface);
    }

}


public class SampleTestTwo extends AbstractSampleTestCase
{
    @Resource
    private SampleInterface sampleInterface;

    @Test
    public void test()
    {
        assertNotNull(sampleInterface);
    }

}


@RunWith(Suite.class)
@SuiteClasses(
{ SampleTestOne.class, SampleTestTwo.class })
public class SampleTestSuite
{
}

AbstractSampleTest, runner spring , spring SpringJunitSuiteRunner, , a SpringJunitParameterizedRunner.

+7

All Articles