I have an Application Class
@SpringBootApplication
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I have a controller class
@RestController
public class HelloController {
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
}
And, I want to write a test case for Application Test, to make sure that instance is created of type HelloController
@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTest{
@Autowired
private HelloController helloController;
@Test
public void test(){
assertNotNull(helloController);
}
}
But, Im getting an error while auto wiring hellocontroller variable(No beans of helloController type found) . As per my understanding @SpringBootTest should create context and return an instance. We dont need to write any context xml or use any AnnotationConfig class to get the instance. What is missing?