java - Test that startup an Spring-boot application -
i have junit test starts spring-boot application (in case, main class springtestdemoapp
) after test:
@webintegrationtest @runwith(springjunit4classrunner.class) @springapplicationconfiguration(classes = springtestdemoapp.class) public class springtest { @test public void test() { // test http://localhost:8080/ (with selenium) } }
everything works fine using spring-boot 1.3.3.release
. nevertheless, annotation @webintegrationtest
, @springapplicationconfiguration
have been removed in spring-boot 1.5.2.release
. tried refactor code new version, not able it. following test, app not started before test , http://localhost:8080 returns 404:
@runwith(springrunner.class) @springboottest(classes = springtestdemoapp.class) @webappconfiguration public class springtest { @test public void test() { // same test before } }
how can refactor test make works in spring-boot 1.5?
the webenvironment option inside @springboottest important. can take values none, mock, random_port, defined_port.
none create spring beans not mock servlet environment.
mock create spring beans , mock servlet environment.
random_port start actual servlet container on random port, can autowired using @localserverport.
defined_port take defined port in properties , start server on them. default random_port when u dont define webenvironment. app may starting in different port u.
try override defined_port , try or else try autowire port no , try run test on port.
Comments
Post a Comment