Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bcarun/761478780014c7a9c5827a320cf7c14e to your computer and use it in GitHub Desktop.
Save bcarun/761478780014c7a9c5827a320cf7c14e to your computer and use it in GitHub Desktop.
Class to make Cucumber use Spring Context for test scenario execution
package com.arun.cucumber.hello.bdd;
import com.arun.cucumber.hello.Application;
import cucumber.api.java.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.ContextConfiguration;
/**
* Class to use spring application context while running cucumber
*/
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@ContextConfiguration(classes = Application.class, loader = SpringBootContextLoader.class)
public class CucumberSpringContextConfiguration {
private static final Logger LOG = LoggerFactory.getLogger(CucumberSpringContextConfiguration.class);
/**
* Need this method so the cucumber will recognize this class as glue and load spring context configuration
*/
@Before
public void setUp() {
LOG.info("-------------- Spring Context Initialized For Executing Cucumber Tests --------------");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment