0

I am doing some Junit testing in Spring and in my Test Class I have to use some test data.

I searched google and there are many ways like - Parameterized Class, TestNG Data Providers, [junit-dataprovider][1] etc.

I though to try TestNG data Provider and created a simple class for my test data as below:

@ContextConfiguration(classes = TestConfiguration.class)
public class TestNgDataProvider extends AbstractTestNGSpringContextTests {
    private static final Logger LOGGER = LoggerFactory.getLogger(TestNgDataProvider.class);

    @DataProvider(name = "invoices")
    public static Object[][] dataProviderMethod() {
        return new Object[][]{
                {"201628JP00006097", "201628JP00006098"},
        };
    }

    @Test(dataProvider = "invoices")
    public void testParameterMethod(String invoiceId1, String invoiceId2) {
        LOGGER.info("Start test");
        LOGGER.info("Test data is: {}, {}", invoiceId1, invoiceId2);

    }
}

However now when I try to use this provider in my Test Class I get an exception saying: java.lang.Exception: No runnable methods

My Test Class is using runWith SpringJUnit4ClassRunner. Anybody knows how to resolve this issue.

import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.testng.annotations.Test;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(TestConfiguration.class)
public class TestLax extends LaxBaseTest {
  @Test (dataProvider="invoices", dataProviderClass=TestNgDataProvider.class)
    public void testLarsTamara(String invoiceId1, String invoiceId2) throws Exception {
        LOGGER.info("Test data is: {}, {}", invoiceId1, invoiceId2);

        File file = larsRemote.runLars();
        readAndVerifyLarsFile(file);
    }
}

1 Answer 1

0

Of course you can't !

JUnit is not able to run TestNG tests or features. But at the opposite, TestNG is able to run junit tests.

Just run your tests with the testng way and it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.