Yes it is. First, let's think about getting your services up automatically. For this, we will use two annotations, one informing the Spring "executor", which is @RunWith(SpringRunner.class)
, and another informing that our port is defined by the non-random configuration file, besides informing our class with the main method that publishes the web service, which is @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, classes = RestfulApplication.class)
. So assuming we're going to test the resource person of your RESTFul web service:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
classes = RestfulApplication.class)
public class PessoaResourceTest {
//...
}
But that does not solve everything. The settings that will be used to launch the service will default to the application.properties
file and the test
profile is desired. For this we will use the tag @ActiveProfiles("test")
:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT,
classes = RestfulApplication.class)
@ActiveProfiles("test")
public class PessoaResourceTest {
//...
}
Now the service will automatically launch using the test
profile before the tests are run.