spring boot - Null Pointer when using @SpringBootTest -
i using spring boot 1.4,
when using @springboottest annotation integration test, gives null pointer.
@runwith(springrunner.class); @springboottest public class mycontrollertest { @test public void mytest { when(). get("/hello"). then(). body("hello"); } }
and main class:
@springapplication @enablecaching @enableasync public class helloapp extends asyncconfiguresupport { public static void main(string[] args) { springapplication.run(helloapp.class, args); } @override public executor getasyncexecutor() { ... } }
then in controller:
@restcontroller public class hellocontroller { @autowired private helloservice helloservice; @requestmapping("/hello"); public string hello() { return helloservice.sayhello(); } }
helloservice
@service public class helloservice { public string sayhello() { return "hello"; } }
but ways says nullpointexception when helloservice when processing request.
what missing?
you need mock helloservice in test class controller calling service .here in case test class not aware there service available or not
Comments
Post a Comment