Why are my cucumber tests cases getting skipped? - java

I am using Cucumber testing framing with spring-rest web service. I am using standard cucumber JUnit framework and Gradle build tool.
Here are the dependencies
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('info.cukes:cucumber-java:1.2.4')
testCompile('info.cukes:cucumber-junit:1.2.4')
testCompile ("info.cukes:cucumber-spring:1.2.4")
testCompile('org.springframework.security:spring-security-test')
Here is my feature file, location of feature file is src/main/resources/feature/addition.feature
Feature: Testing a REST API
Users should be able to add two numbers
Scenario: number addition service
When baseUri is /messages/add
Then result should be 3
Here is my step definition code. it resides in test/java/somepackage/
public class StepDefinition {
#When("^baseUri is (.*)$")
public void baseUri(String uri) {
}
#Then("result should be (\\d+)")
public void checkResult(int result){
Assert.assertEquals(result, this.result);
}
}
My test runner class is, test runner and StepDefinition both are in the same package in /test/java
#RunWith(Cucumber.class)
#CucumberOptions(features = "classpath:feature/", glue = {"com.example.restdemo.web.StepDefinition"}, format = {"pretty", "html:target/cucumber"})
public class CucumberIntegrationTest {
}
Now when I am running my test runner class i.e CucumberIntegrationTest.java, I am getting following O/P.
"C:\Program Files\Java\jdk1.8.0_144\bin\java" -ea -Didea.test.cyclic.buffer.size=1048576 -javaagent:C:\Users\govindas\Downloads\ideaIU-2017.2.5.win\lib\idea_rt.jar=52114:C:\Users\govindas\Downloads\ideaIU-2017.2.5.win\bin -Dfile.encoding=UTF-8 -classpath "C:\Users\govindas\Downloads\ideaIU-2017.2.5.win\lib\idea_rt.jar;C:\Users\govindas\Downloads\ideaIU-2017.2.5.win\plugins\junit\lib\junit-rt.jar;C:\Users\govindas\Downloads\ideaIU-2017.2.5.win\plugins\junit\lib\junit5-rt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_144\jre\lib\rt.jar;C:\Users\govindas\IdeaProjects\restdemo\out\test\classes;C:\Users\govindas\IdeaProjects\restdemo\out\production\classes;C:\Users\govindas\IdeaProjects\restdemo\out\production\resources;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-cache\1.5.7.RELEASE\98480d5e70a79ff279ea0bb156f2d18222ba8211\spring-boot-starter-cache-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-data-rest\1.5.7.RELEASE\cc092ea664a736c5fdf6077dd86f3459bcdd8caa\spring-boot-starter-data-rest-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-hateoas\1.5.7.RELEASE\be7eb70b2ac27fb270278530238323e441afd1cf\spring-boot-starter-hateoas-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-jdbc\1.5.7.RELEASE\98c652a5461ccbec70b55fd0f7815d9c9a37a082\spring-boot-starter-jdbc-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-jersey\1.5.7.RELEASE\dc608d6e96755fdad671da5f9a11f86b345fe30d\spring-boot-starter-jersey-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-security\1.5.7.RELEASE\e680aa1a8990a6e98e7a843c88f0a8bc378bb4d\spring-boot-starter-security-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-web\1.5.7.RELEASE\a862305be8b7512a41f6768d825ed37251ccbbe0\spring-boot-starter-web-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-test\1.5.7.RELEASE\d23f37a72c2d4e46aba66bc69a649213f9cadeee\spring-boot-starter-test-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\info.cukes\cucumber-spring\1.2.4\f3cff393c13087ac43e11936a90ec0c8792c534\cucumber-spring-1.2.4.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\info.cukes\cucumber-java\1.2.4\57cca534b7abe43f6dd7624b90d3d97d33d3023d\cucumber-java-1.2.4.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.apache.derby\derby\10.13.1.1\29c42babe5c5463c6eea45487d3cfbfe8348ccd1\derby-10.13.1.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\info.cukes\cucumber-junit\1.2.4\8a57b68486cff4da4f10019cb9c62c597a6d2861\cucumber-junit-1.2.4.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-test\4.2.3.RELEASE\f93339f597290d85a596f25a7841b9109b79ced6\spring-security-test-4.2.3.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-validation\1.5.7.RELEASE\a2e87bf66a1db8037e1feeba7e7063996fa72090\spring-boot-starter-validation-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter\1.5.7.RELEASE\b42fe6962dd8b3be4ac8c1d7134d0ca2d0a35c7e\spring-boot-starter-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context-support\4.3.11.RELEASE\a74bdcbce2b35804cdfdac1ca820820100b5fd9b\spring-context-support-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-rest-webmvc\2.6.7.RELEASE\9a638b76b290b52a241b59a7341a042a063bad3d\spring-data-rest-webmvc-2.6.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-rest-core\2.6.7.RELEASE\fe15f604fa9b35f16af608c05266fcba53a7d17c\spring-data-rest-core-2.6.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.hateoas\spring-hateoas\0.23.0.RELEASE\678ffa0798f417a794fea592dc8066e325611919\spring-hateoas-0.23.0.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.plugin\spring-plugin-core\1.2.0.RELEASE\f380e7760032e7d929184f8ad8a33716b75c0657\spring-plugin-core-1.2.0.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-config\4.2.3.RELEASE\9f3771903616e33521836fd999d63efbfebf90d\spring-security-config-4.2.3.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-web\4.2.3.RELEASE\7a03e737484ca232d7146852f06d067ac21427ac\spring-security-web-4.2.3.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-webmvc\4.3.11.RELEASE\814f91ec4dc324e724bbe7cbc5045b234604c539\spring-webmvc-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.security\spring-security-core\4.2.3.RELEASE\5c0e47a47036c94d6fdd02696bf52be6d1adbd4d\spring-security-core-4.2.3.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-test-autoconfigure\1.5.7.RELEASE\8bead16b97c9f1b5fe7c47f3e030dd9351a6974d\spring-boot-test-autoconfigure-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-test\1.5.7.RELEASE\b8d77445d48f4320f404d8f13f4e5cb95bc36b30\spring-boot-test-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-autoconfigure\1.5.7.RELEASE\e83f1407ff991e9e7eb156f49fa19d868bb73289\spring-boot-autoconfigure-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot\1.5.7.RELEASE\1006870df7b3dc203df7ce84463c5dd7049fdaa4\spring-boot-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.ext\jersey-spring3\2.25.1\a31bfcd2fcae5beb979d3f41079b6f4020d6fbc9\jersey-spring3-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\spring-bridge\2.5.0-b32\f38ecef23edc769942a95c062efd63541044de42\spring-bridge-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-web\4.3.11.RELEASE\50a3dfce550bdf9459dfb2c6282aa104b040258e\spring-web-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-context\4.3.11.RELEASE\3efec2d7c7469d49108a2b21c3f15831f7297569\spring-context-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.media\jersey-media-json-jackson\2.25.1\19d1e4276eb7b6386640c344d9e5c01eba7eae5d\jersey-media-json-jackson-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.jaxrs\jackson-jaxrs-json-provider\2.8.10\f8837cf03871569eb02a491dea64929e5da14b4\jackson-jaxrs-json-provider-2.8.10.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.jaxrs\jackson-jaxrs-base\2.8.10\50a3d02a31cb427272a96fe696b5ac9442c7cfa1\jackson-jaxrs-base-2.8.10.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.module\jackson-module-jaxb-annotations\2.8.10\22df8efd0cff7661bf136148c73e2651748f7600\jackson-module-jaxb-annotations-2.8.10.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.8.10\f7b83cb2bc4b88d53961e749e1ad32f49ef017b7\jackson-databind-2.8.10.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.8.0\45b426f7796b741035581a176744d91090e2e6fb\jackson-annotations-2.8.0.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.apache.tomcat\tomcat-jdbc\8.5.20\10d0d288d837ddfc92096920e4571054a3934160\tomcat-jdbc-8.5.20.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-jdbc\4.3.11.RELEASE\642ed7497d327f299caccb930af6b65e229864c4\spring-jdbc-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-tomcat\1.5.7.RELEASE\eae533e2a0111a51d812912acb3d3e2368736d1b\spring-boot-starter-tomcat-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.containers\jersey-container-servlet\2.25.1\cf5f7a76fcea38158b890ab7a0142d4db709a882\jersey-container-servlet-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.containers\jersey-container-servlet-core\2.25.1\400e30bb035a0cdf3c554530224141ce659a0d1e\jersey-container-servlet-core-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.ext\jersey-bean-validation\2.25.1\1971927d79cad0ad2b5a3bfda24967748a2023d\jersey-bean-validation-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.core\jersey-server\2.25.1\276e2ee0fd1cdabf99357fce560c5baab675b1a2\jersey-server-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-aop\4.3.11.RELEASE\461d0bb58f1de30203d9331adf4b51de9554de5a\spring-aop-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\hk2\2.5.0-b32\c3accae585955e49c771d464899e906ecc9ffb4\hk2-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\config-types\2.5.0-b32\686bbe7f80b1b879d64c06bc6606c97721a795f2\config-types-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\hk2-config\2.5.0-b32\dce05ac4225dbc0c1c382ad02e3b5bee51f0168a\hk2-config-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.hibernate\hibernate-validator\5.3.5.Final\622a9bcef2eed6d41b5b8e0662c36212009e375\hibernate-validator-5.3.5.Final.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.jayway.jsonpath\json-path\2.2.0\22290d17944bd239fabf5ac69005a60a7ecbbbcb\json-path-2.2.0.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\junit\junit\4.12\2973d150c0dc1fefe998f834810d68f278ea58ec\junit-4.12.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.assertj\assertj-core\2.6.0\b532c3fc4f66bcfee4989a3514f1cd56203a33ad\assertj-core-2.6.0.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.mockito\mockito-core\1.10.19\e8546f5bef4e061d8dd73895b4e8f40e3fe6effe\mockito-core-1.10.19.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-library\1.3\4785a3c21320980282f9f33d0d1264a69040538f\hamcrest-library-1.3.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.skyscreamer\jsonassert\1.4.0\9cdbb373a06f6513e51e8c545ee6a5e981463edb\jsonassert-1.4.0.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-test\4.3.11.RELEASE\cf765b5d6d6bdc38c67522ecae3fe9549da43e1\spring-test-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-tx\4.3.11.RELEASE\c931ee363d2269f03edfeb83d7d7fe23924ab8a1\spring-tx-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.data\spring-data-commons\1.13.7.RELEASE\cf4538abda1f0a9cf2323d6e4204df0130aeec73\spring-data-commons-1.13.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-beans\4.3.11.RELEASE\591cc35fd39292adae13f01aa13e978d0bb11936\spring-beans-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-expression\4.3.11.RELEASE\fca662a2fccdad90ec22b2aaecb021047dcbe249\spring-expression-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework\spring-core\4.3.11.RELEASE\eb30ed093f628279d3aead068fd478fa343f1dad\spring-core-4.3.11.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\info.cukes\cucumber-core\1.2.4\72790b1da44d8d3d2764c6aef29865ee228bbeb1\cucumber-core-1.2.4.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.springframework.boot\spring-boot-starter-logging\1.5.7.RELEASE\c84c4ea09d7f789a0d5e936a961471e5dbd9295e\spring-boot-starter-logging-1.5.7.RELEASE.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.yaml\snakeyaml\1.17\7a27ea250c5130b2922b86dea63cbb1cc10a660c\snakeyaml-1.17.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.8.10\eb21a035c66ad307e66ec8fce37f5d50fd62d039\jackson-core-2.8.10.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.slf4j\jcl-over-slf4j\1.7.25\f8c32b13ff142a513eeb5b6330b1588dcb2c0461\jcl-over-slf4j-1.7.25.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-classic\1.1.11\ccedfbacef4a6515d2983e3f89ed753d5d4fb665\logback-classic-1.1.11.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.slf4j\jul-to-slf4j\1.7.25\af5364cd6679bfffb114f0dec8a157aaa283b76\jul-to-slf4j-1.7.25.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.slf4j\log4j-over-slf4j\1.7.25\a87bb47468f47ee7aabbd54f93e133d4215769c3\log4j-over-slf4j-1.7.25.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.25\da76ca59f6a57ee3102f8f9bd9cee742973efa8a\slf4j-api-1.7.25.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.apache.tomcat\tomcat-juli\8.5.20\6c0579d329696059f377585d2a51455bf083d9ee\tomcat-juli-8.5.20.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-websocket\8.5.20\4df9055507926a2651f691cc9964c50493a0ab29\tomcat-embed-websocket-8.5.20.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-core\8.5.20\b9026ee20f1f6a2b0fc3e51dd806d800901448b0\tomcat-embed-core-8.5.20.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.apache.tomcat.embed\tomcat-embed-el\8.5.20\42960f481a8a80f4ffd3b865c2232820e3565bf1\tomcat-embed-el-8.5.20.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.core\jersey-client\2.25.1\4d563b1f93352ee9fad597e9e1daf2c6159993c6\jersey-client-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.media\jersey-media-jaxb\2.25.1\d7da0beeed5614a3bfd882662faec602699e24b\jersey-media-jaxb-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.core\jersey-common\2.25.1\2438ce68d4907046095ab54aa83a6092951b4bbb\jersey-common-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.ext\jersey-entity-filtering\2.25.1\4a5805060f796ec2c9bb1ba0ce91c1db6d889524\jersey-entity-filtering-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\javax.ws.rs\javax.ws.rs-api\2.0.1\104e9c2b5583cfcfeac0402316221648d6d8ea6b\javax.ws.rs-api-2.0.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\javax.annotation\javax.annotation-api\1.2\479c1e06db31c432330183f5cae684163f186146\javax.annotation-api-1.2.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\hk2-core\2.5.0-b32\8cb6a8a9522ec523b7740d29f555bdbe9d936af2\hk2-core-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\hk2-runlevel\2.5.0-b32\60dc979763ea885e796cba4d3e322af8d500ba74\hk2-runlevel-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\hk2-locator\2.5.0-b32\195474f8ad0a8d130e9ea949a771bcf1215fc33b\hk2-locator-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\hk2-api\2.5.0-b32\6a576c9653832ce610b80a2f389374ef19d96171\hk2-api-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2.external\javax.inject\2.5.0-b32\b2fa50c8186a38728c35fe6a9da57ce4cc806923\javax.inject-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\javax.validation\validation-api\1.1.0.Final\8613ae82954779d518631e05daa73a6a954817d5\validation-api-1.1.0.Final.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\aopalliance\aopalliance\1.0\235ba8b489512805ac13a8f9ea77a1ca5ebe3e8\aopalliance-1.0.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.jboss.logging\jboss-logging\3.3.1.Final\c46217ab74b532568c0ed31dc599db3048bd1b67\jboss-logging-3.3.1.Final.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.fasterxml\classmate\1.3.4\3d5f48f10bbe4eb7bd862f10c0583be2e0053c6\classmate-1.3.4.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\net.minidev\json-smart\2.2.1\5b9e5df7a62d1279b70dc882b041d249c4f0b002\json-smart-2.2.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.objenesis\objenesis\2.1\87c0ea803b69252868d09308b4618f766f135a96\objenesis-2.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\com.vaadin.external.google\android-json\0.0.20131108.vaadin1\fa26d351fe62a6a17f5cda1287c1c6110dec413f\android-json-0.0.20131108.vaadin1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\info.cukes\cucumber-html\0.2.3\624a0c986088e32910336dd77aee5191c04a8201\cucumber-html-0.2.3.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\info.cukes\cucumber-jvm-deps\1.0.5\69ed0efe4b81f05da3c0bdc7281cbdc43f5ceb26\cucumber-jvm-deps-1.0.5.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\info.cukes\gherkin\2.12.2\17138631fa20fd0e44a13e50d6b7be59cee1a94\gherkin-2.12.2.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.atteo\evo-inflector\1.2.2\2551aad98d65ac5464d81fe05f0e1516cfe471c9\evo-inflector-1.2.2.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.jersey.bundles.repackaged\jersey-guava\2.25.1\a2bb4f8208e134cf2cf71dfb8824e42942f7bd06\jersey-guava-2.25.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\osgi-resource-locator\1.0.1\4ed2b2d4738aed5786cfa64cba5a332779c4c708\osgi-resource-locator-1.0.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\hk2-utils\2.5.0-b32\5108a926988c4ceda7f1e681dddfe3101454a002\hk2-utils-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2.external\aopalliance-repackaged\2.5.0-b32\6af37c3f8ec6f9e9653ec837eb508da28ce443cd\aopalliance-repackaged-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.javassist\javassist\3.21.0-GA\598244f595db5c5fb713731eddbb1c91a58d959b\javassist-3.21.0-GA.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2\class-model\2.5.0-b32\17f054f3e91898c0c0fc52163ad904b13c24e8b\class-model-2.5.0-b32.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\net.minidev\accessors-smart\1.1\a527213f2fea112a04c9bdf0ec0264e34104cd08\accessors-smart-1.1.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\ch.qos.logback\logback-core\1.1.11\88b8df40340eed549fb07e2613879bf6b006704d\logback-core-1.1.11.jar;C:\Users\govindas\.gradle\caches\modules-2\files-2.1\org.glassfish.hk2.external\asm-all-repackaged\2.5.0-b32\dc705f1d54cd5a96cbc5a473525e75ef1cb59a9e\asm-all-repackaged-2.5.0-b32.jar;C:\Users\xyz\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm\5.0.3\dcc2193db20e19e1feca8b1240dbbc4e190824fa\asm-5.0.3.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.example.restdemo.web.CucumberIntegrationTest
Feature: Testing a REST API
Users should be able to add two numbers
19:00:03.815 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Registering scope 'cucumber-glue' with implementation [cucumber.runtime.java.spring.GlueCodeScope#2a54a73f]
Test ignored.
Test ignored.
Test ignored.
Test ignored.
Scenario: number addition service # feature/addition.feature:4
When baseUri is /messages/add
Then result should be 3
1 Scenarios (1 undefined)
2 Steps (2 undefined)
0m0.000s
You can implement missing steps with the snippets below:
#When("^baseUri is /messages/add$")
public void baseuri_is_messages_add() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#Then("^result should be (\\d+)$")
public void result_should_be(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Process finished with exit code 0

Remove the class name from the glue attribute
#CucumberOptions(features = "classpath:feature/", glue = {"com.example.restdemo.web"}, format = {"pretty", "html:target/cucumber"})

Related

Jacoco classes in bundle do not match for Transactional methods

I'm testing an app with JUnit5 and using Jacoco for coverage report.
Tests are executed Ok and test reports are present.
However, Jacoco report has the following logs if service contains methods, annotated with #Transactional
[ant:jacocoReport] Classes in bundle 'my-service' do no match with execution data. For report generation the same class files must be used as at runtime.
[ant:jacocoReport] Execution data for class mypackage/SampleService does not match.
This error occurres for all #Service classes methods, annotated with #Transactional, plain classes coverage is calculated ok.
Here's a sample test:
#SpringBootTest
#ExtendWith(SpringExtension.class)
public class MyServiceTest {
#Autowired
private SampleService sampleService;
#Test
public void doWork(){
sampleService.doWork();
}
}
Works fine. Coverage is non-zero:
public class SampleService {
public void doWork(){
System.out.println("HEY");
}
}
0% coverage:
public class SampleService {
#Transactional
public void doWork(){
System.out.println("HEY");
}
}
Transactional creates a proxy around actuall class. But, isn't there an out-of-box way for Jacoco to handle such a common situation?
I've tried #EnableAspectJAutoProxy annotaion with different flag variations, checked that up-to-date Jupiter engine and Jacoco plugin are used
Here's gradle config:
subprojects {
test {
useJUnitPlatform()
}
jacocoTestReport {
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
fileTree(dir: it, exclude: '*Test.java')
})
}
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
}
Any help appreciated
I tried it with a test project, similar to what you've described, however I couldn't reproduce the issue. The only difference that I see between your project and mine, is that I've used maven instead of gradle.
Here is the test project:
https://github.com/gybandi/jacocotest
And here is the jacoco result for it (using org.springframework.transaction.annotation.Transactional annotation):
If this doesn't help you, could you upload your test project to github or some other place?
Edit:
#MikaelF posted a link to another answer, which shows how to add offline instrumentation for jacoco.
The solution that was described there worked for me, after I added the following block to build.gradle:
task instrument(dependsOn: [classes, project.configurations.jacocoAnt]) {
inputs.files classes.outputs.files
File outputDir = new File(project.buildDir, 'instrumentedClasses')
outputs.dir outputDir
doFirst {
project.delete(outputDir)
ant.taskdef(
resource: 'org/jacoco/ant/antlib.xml',
classpath: project.configurations.jacocoAnt.asPath,
uri: 'jacoco'
)
def instrumented = false
if (file(sourceSets.main.java.outputDir).exists()) {
def instrumentedClassedDir = "${outputDir}/${sourceSets.main.java}"
ant.'jacoco:instrument'(destdir: instrumentedClassedDir) {
fileset(dir: sourceSets.main.java.outputDir, includes: '**/*.class')
}
//Replace the classes dir in the test classpath with the instrumented one
sourceSets.test.runtimeClasspath -= files(sourceSets.main.java.outputDir)
sourceSets.test.runtimeClasspath += files(instrumentedClassedDir)
instrumented = true
}
if (instrumented) {
//Disable class verification based on https://github.com/jayway/powermock/issues/375
test.jvmArgs += '-noverify'
}
}
}
test.dependsOn instrument
There seems to be an open ticket on the jacoco plugin's github about this as well:
https://github.com/gradle/gradle/issues/2429
Based on single module instrumentation example https://stackoverflow.com/a/31916686/7096763 (and updated version for gradle 5+ by #MikaelF) here's example for multimodule instrumentation:
subprojects { subproject ->
subproject.ext.jacocoOfflineSourceSets = [ 'main' ]
task doJacocoOfflineInstrumentation(dependsOn: [ classes, subproject.configurations.jacocoAnt ]) {
inputs.files classes.outputs.files
File outputDir = new File(subproject.buildDir, 'instrumentedClasses')
outputs.dir outputDir
doFirst {
project.delete(outputDir)
ant.taskdef(
resource: 'org/jacoco/ant/antlib.xml',
classpath: subproject.configurations.jacocoAnt.asPath,
uri: 'jacoco'
)
def instrumented = false
jacocoOfflineSourceSets.each { sourceSetName ->
if (file(sourceSets[sourceSetName].output.classesDirs[0]).exists()) {
def instrumentedClassedDir = "${outputDir}/${sourceSetName}"
ant.'jacoco:instrument'(destdir: instrumentedClassedDir) {
fileset(dir: sourceSets[sourceSetName].output.classesDirs[0], includes: '**/*.class')
}
//Replace the classes dir in the test classpath with the instrumented one
sourceSets.test.runtimeClasspath -= files(sourceSets[sourceSetName].output.classesDirs[0])
sourceSets.test.runtimeClasspath += files(instrumentedClassedDir)
instrumented = true
}
}
if (instrumented) {
//Disable class verification based on https://github.com/jayway/powermock/issues/375
test.jvmArgs += '-noverify'
}
}
}
test.dependsOn doJacocoOfflineInstrumentation
}
full example here:
https://github.com/lizardeye/jacocomultimodulesample
Still, I think this is a durty hack, which can be easily broken with gradle or jacoco updates

How to print full path to script files in #sql annotation in spring boot test

In a multi-module project I want to be sure that Spring's #sql annotation uses correct resources. Is there a way to log full path of those files to console somehow?
Spring does log script file name before execution, but in tests for different modules those file names are the same sometimes.
SqlScriptsTestExecutionListener - responsible for the processing of #Sql, for the first step you can change to debug related log by adding property logging.level.org.springframework.test.context.jdbc=debug, but the debug message is not fully and if is not enough you should create your own TestExecutionListener and declare on test class #TestExecutionListeners(listeners = SqlScriptsCustomTestExecutionListener.class)
for example:
public class SqlScriptsCustomTestExecutionListener extends AbstractTestExecutionListener {
#Override
public void beforeTestMethod(TestContext testContext) {
List<Resource> scriptResources = new ArrayList<>();
Set<Sql> sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(testContext.getTestMethod(), Sql.class);
for (Sql sqlAnnotation : sqlAnnotations) {
String[] scripts = sqlAnnotation.scripts();
scripts = TestContextResourceUtils.convertToClasspathResourcePaths(testContext.getTestClass(), scripts);
scriptResources.addAll(TestContextResourceUtils.convertToResourceList(testContext.getApplicationContext(), scripts));
}
if (!scriptResources.isEmpty()) {
String debugString = scriptResources.stream().map(r -> {
try {
return r.getFile().getAbsolutePath();
} catch (IOException e) {
System.out.println("Unable to found file resource");
}
return null;
}).collect(Collectors.joining(","));
System.out.println(String.format("Execute sql script :[%s]", debugString));
}
}
It is just quick example and it works. Most of source code i copied from SqlScriptsTestExecutionListener just for explanation. It is just realization in case of #Sql annotation on method level, and not included class level.
I hope it will be helps you.

Maven doesn't initialize the spring context property when running integration tests

Issue : When running integration tests from maven (mvn verify) the spring application context is not initialized properly, it doesn't take in consideration my custom ApplicationContextInitializer class.
Test Class :
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = {MainApplication.class}, initializers = CustomContextInitializer.class)
#WebIntegrationTest
public class ApplicationIT {
// Running a SOAPUI suite as a JUnit Test
#Test
public void TestGateway() throws Exception {
SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
runner.setProjectFile("../gateway/src/test/resources/soapui/gateway-soapui.xml");
runner.run();
}
}
MainApplication class :
#Configuration
#ComponentScan(basePackages = {
// different packages here (not relevant)
})
#EnableAutoConfiguration
public class MainApplication {
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder(MainApplication.class)
.initializers(new CustomContextInitializer())
.run(args);
}
}
CustomContextInitiliazer class (for adding custom .properties files to the spring environment application context) :
public class CustomContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext>{
#Override
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment env = applicationContext.getEnvironment();
try {
Resource[] res = new PathMatchingResourcePatternResolver().getResources("classpath*:/*.properties");
for (Resource re : res) {
env.getPropertySources().addFirst(new ResourcePropertySource(re));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Results :
1) Everything works on when I start and run the application (either from IDE or by invoking mvn exec).
2) Integration tests run ok when started from IDE.
3) Integration tests throw error when invoked via maven verify because the custom properties files are not loaded into spring context environment. The result is the same as if I wouldn't have written initializers = CustomContextInitializer.class in the test class and tried to run the tests from IDE.
I think your code is correct, but your .properties files may be at the wrong place. Make sure they are under <project>/src/main/resources or that you have configured a custom resource folder in maven. If they reside under <project>/src/main/java they will not be part of the classpath as far as maven is concerned.

gradle test runs my test class, but not a custom test task

This is my test class:
public class RoutingResponseRegressionOneByOne {
#BeforeClass
public static void oneTimeSetUp() {
routingClient = injector.getInstance(IRoutingClient.class);
System.out.println("in RoutingResponseRegressionOneByOne:: oneTimeSetUp");
}
I added a task to my build.gradle
task testRegression(type: Test) {
systemProperties['test.single'] = '\'RoutingResponseRegressionOneByOne\''
//systemProperty 'test.single', System.getProperty('test.single', '\'RoutingResponseRegressionOneByOne\'')
}
When I run "test" from the intellij this is the output
however when I "testRegression" from the intellij this is the output:
what should I fix in order for "testRegression" to run only this test class ?
You can pass an argument to your task with P and use the TestFilter.
In this link you will find a complete example for the filter usage. Below I attached a code of a custom automationTest task that runs tests from a specific folder.
task automationTest(type: Test) {
//search for an argument called 'single'. if exists, use it as a test filter
if (project.hasProperty('single')) {
filter {
includeTestsMatching "*${project.property('single')}*"
}
}
useTestNG()
description = "Runs Automation Tests"
testClassesDir = file("$buildDir/classes/main/automation")
classpath += sourceSets.main.runtimeClasspath
}
run it as: gradle -Psingle=MyTest automationTest

HtmlUnit - Class not found in src folder but run in test folder

I am programming in Java using Maven/Eclipse.
I am able to run HtmlUnit fine when running from a Unit Test. (test/)
However when I try to use the same code in the src/ folder, I receive java.lang.NoClassDefFoundError messages. The only way I have been able to resolve them is to go and manually add all the jars to the build path. But this doesn't make sense to me as the jar file shows up in my Maven Dependencies.
pom.xml (there are more dependencies in the actual pom file)
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.9</version>
<scope>test</scope>
</dependency>
The Sample block of HtmlUnit code
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage(url);
System.out.println("Executing Pages JavaScript for " + config.executeJavaScriptTime + " seconds..."); webClient.waitForBackgroundJavaScript(config.executeJavaScriptTime);
dom = cleaner.clean(page.asXml());
html = cleaner.getInnerHtml(dom);
webClient.closeAllWindows();
Any Ideas? Thanks.
The test scope which is applied to your dependency means that it is not available on the compile classpath. This way, the code you ship does not depend on test code. A more complete explanation can be found here. If the project you are building is intended to be only tests, you should remove the scope tag to let it take the default scope, compile. But in general it is correct that your shipping code, built from src, shouldn't depend on JUnit, a testing library.
As of now the only working hack I have found is to create a method annotated as #Test and run the crawler as a JUnit Test.
i.e.
public class Crawler() {
#Test
public void runAsTest() {
Crawler crawler = new Crawler();
String[] urls = new String[]{
"http://www.url.com/1",
"http://www.url.com/2",
"http://www.url.com/3"
};
crawler.crawl(urls);
try {
Thread.sleep(1000 * 60 * 15); // without this the unit test exits too early
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// the rest of the class definition
}
I would like to be able to run this from a standard main method, i.e.
public class Crawler() {
public static void main(String[] args) {
Crawler crawler = new Crawler();
String[] urls = new String[]{
"http://www.url.com/1",
"http://www.url.com/2",
"http://www.url.com/3"
};
crawler.crawl(urls);
try {
Thread.sleep(1000 * 60 * 15); // without this the unit test exits too early
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// the rest of the class definition
}

Categories

Resources