title: Testing Spring boot application with Cucumber
body: <p>My requirement is to Test my Spring boot application using BDD. I chose cucumber for this purpose. While looking for any tutorial that would help me do this, i came across many and i end up confusing myself. Below are my requirements</p>
  
  <ol>
  <li><p>I want to be able to test my application while building it using <code>mvn test</code> from command line</p></li>
  <li><p>I want do previous step in my build server as well.</p></li>
  </ol>
  
  <p>My expectation was if I simply run <code>mvn test</code> then maven should fireup my application and will execute my features step by step but in actually it doesn't start my application, instead it run the test, which expects my application to be running and it tries to consume those services. Below is my Cucumber Test class</p>
  
  <pre><code>@RunWith(Cucumber.class)
  @CucumberOptions(features = "src/test/resources/features",
          glue="com.api.resources.steps",
          format = {
                  "pretty",
                  "html:target/cucumber-reports/cucumber-pretty",
                  "json:target/cucumber-reports/CucumberTestReport.json",
                  "rerun:target/cucumber-reports/rerun.txt"
          }
  )
  public class ApiTests {
  }
  </code></pre>
  
  <p>My FeatureStep class</p>
  
  <pre><code>@TestConfigs
  public class FacebookAuthentication{
      public static final String HOST="http://localhost:8080";
      @Given("^User requests authentication by providing \"([^\"]*)\" and \"([^\"]*)\" obtained from facebook$")
      public void userRequestsAuthenticationByProvidingAndObtainedFromFacebook(String arg0, String arg1) throws Throwable {
          String token = "token";
          String id = "id";
          Map&lt;String, String&gt; map = new HashMap&lt;&gt;();
          map.put("token",token);
          map.put("id",id");
          String response = HttpUtilForTests.sendPostRequest(HOST+"/auth/facebook", map, "");
      }
  
      @When("^Facebook returns User details with \"([^\"]*)\" \"([^\"]*)\" and \"([^\"]*)\"$")
      public void facebookReturnsUserDetailsWithAnd(String arg0, String arg1, String arg2) throws Throwable {
  
      }
  
      @Then("^User should be authorized in pixyfi application and return User info with UserToken$")
      public void userShouldBeAuthorizedInPixyfiApplicationAndReturnUserInfoWithUserToken() throws Throwable {
          Assert.assertTrue(true);
      }
  }
  </code></pre>
  
  <p>My Test Config</p>
  
  <pre><code>@Target(ElementType.TYPE)
  @Retention(RetentionPolicy.RUNTIME)
  @ContextConfiguration
  @ActiveProfiles("test")
  @SpringBootTest(
          webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
          classes = GlobalTestonfig.class)
  public @interface TestConfigs {
  
  }
  
  @Configuration
  @Import(MyApplication.class)
  class GlobalTestonfig {
  
  }
  </code></pre>
  
  <p>With above settings <code>mvn test</code> start my tests but consuming service at <a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a> fails as the service itself is not started. 
  could you please help me out here with where exactly i'm mistaking?</p>