@RunWith(SpringRunner.class)
@SpringBootTest(classes = GetServerPortApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@ActiveProfiles("fixedport")
public class GetServerFixedPortUnitTest {
private final static int EXPECTED_PORT = 7777;
....
}
@RunWith(SpringRunner.class) – This will join the JUnit test with the Spring TestContext
@SpringBootTest( … SpringBootTest.WebEnvironment.DEFINED_PORT) – In the SpringBootTest, we'll use the DEFINED_PORT for the embedded web server
@ActiveProfiles(“fixedport”) – With this annotation, we enabled the Spring profile “fixedport” so that our application-fixedport.properties will be loaded