java - Running SpringBoot application that implements CommandLineRunner with Cuccumber, run's main application before running Feature test cases -


i new cucumber , spring boot,i developeing spring boot application implements commandlinerunner , trying integrate cucumber framework run tests , create corresponding reports. cucumber test cases running fine before running test cases runs springboot application (application.java). expected behaviour or there someway run tests only.

main spring boot class - application.java class:-

/**  * main application class  */ @springbootapplication public class application implements commandlinerunner {  @override  public void run(string... args) {  @autowired     private gwmlcontroller gwmlcontroller;      @autowired     private smartxmlcontroller mxmlcontroller;      @autowired     private reportingcontroller reportingcontroller;      @autowired     private comparisionreportcontroller comparisionreportcontroller;     ....     ...     busniess logic  } 

now cucumber class are:-

  1. abstractdefination.java

    package cucumberjava.steps;  import org.junit.runner.runwith; import org.springframework.boot.test.context.springboottest; import org.springframework.test.context.activeprofiles; import org.springframework.test.context.junit4.springrunner; import org.springframework.test.context.web.webappconfiguration;  @runwith(springrunner.class) @activeprofiles("test") @springboottest @autoconfiguremockmvc @webappconfiguration public class abstractdefinitions{      public abstractdefinitions() {     }  } 
  2. testvalidations:-

    import static junit.framework.testcase.assertequals; import static junit.framework.testcase.assertfalse; import static junit.framework.testcase.assertnotnull;  @contextconfiguration(classes = {cucumberconfiguration.class}) public class testvalidations extends abstractdefinitions {  @autowired private gwmlcontroller gwmlcontroller;  @autowired private smartxmlcontroller mxmlcontroller;  @autowired private comparisionreportcontroller comparisionreportcontroller;  @given("^gid map not empty$") public void guid_map_is_not_null() throws throwable {   comparisonresultmap =    comparisionreportcontroller.makecomparisionmappingmap  (comparisonresultmap);  assertfalse(comparisonresultmap.isempty()); } 
  3. cucumberconfiguration .java

    @configuration @componentscan(basepackages = "au.com.nab.mx") public class cucumberconfiguration {  } 

and in build.gradle have:-

 testcompile group: 'org.springframework.boot', name: 'spring-boot-starter-  test', version: '1.5.4.release'  compile group: 'net.sf.supercsv', name: 'super-csv', version: '2.4.0'  compile group: 'info.cukes', name: 'cucumber-java', version: '1.2.5'  compile group: 'info.cukes', name: 'cucumber-core', version: '1.2.5'  compile group: 'info.cukes', name: 'gherkin', version: '2.12.2'  testcompile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'  testcompile group: 'info.cukes', name: 'cucumber-spring', version: '1.2.5'  testcompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5' } 

.feature

feature: validations.feature

  scenario outline: compare_columns     given gid map not empty     when  <smt> not-null , <gwml> not null     <smt> validateequal <gwml>     @smoke    examples:    |  smt             |  gwml             |    |  **smt_guid      |  **gwml_guid      |    |  smt_buy_sell    |  gwml_buy_sell    | 

now issue whenever run application, first runs application.java , runs cucumber test cases.now not sure whether expected befhaviour or missing something.

regards, vikram pathania

usage of @contextconfiguration , @springboottest load application context required testing.

docs : http://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/test/context/springboottest.html


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -