Reputation: 384
I am using spring boot 2.0.1.RELEASE and TestNG for testing. But unable to load spring context and autowire repository. Kindly guide me.
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class ApplictionTestsWithTestNG extends AbstractTestNGSpringContextTests{
@Autowired
MyRepository repo;
@BeforeTest
public void setup() {
System.out.println("repository found "+repo);
}
@Test
public void matchLastSavedData() {
System.out.println("repository found " + repo);
assertEquals(5,5);
}
}
When running, it throws
java.lang.Exception: No runnable methods
at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
Upvotes: 1
Views: 2088
Reputation: 204
For people who using IDEA and testNg or Junit
It is a bit different to create junit or testNg Run/Debug Configuration:
If you mixed up the two types of IDEA test runner, or mixed up annotation you are using, it will output error like: No runnable methods
import org.junit.Test;
import org.junit.runner.RunWith;
@SpringBootTest(...)
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
public class SomethingTest {
@Test
public void testSomemethod() {
}
}
import org.testng.Assert;
import org.testng.annotations.Test;
@SpringBootTest(...)
@ActiveProfiles("test")
public class SomethingTest extends AbstractTestNGSpringContextTests {
@Test
public void testSomemethod() {
}
}
debug your first java application
run debug configuration-testNg
Upvotes: 0
Reputation: 11
@RunWith(SpringJUnit4ClassRunner.class) works with JUnit. Needs to define context configuration which should wire MyRepository bean.
Upvotes: 1
Reputation: 86774
You have no methods annotated @Test
.
There are no tests to run, just as the error message told you.
Write a test method annotated with @Test
.
Upvotes: 1