Thomas Sundberg

May 29, 2014

Cucumber-JVM Hello world!

This post is available at http://www.thinkcode.se/blog/2014/05/29/cucumberjvm-hello-world

Advertisements

20 Comments »

  1. Are you sure your above code runs? There is no feature file defined in your runner class. When i ran, I get the below message:

    T E S T S
    ——————————————————-
    Running se.thinkcode.itake.RunCukesTest
    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.386 sec <<< FAILURE!
    initializationError(se.thinkcode.itake.RunCukesTest) Time elapsed: 0.008 sec <<< ERROR!
    cucumber.runtime.CucumberException: No features found at [classpath:se/thinkcode/itake]
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:47)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:100)
    at cucumber.api.junit.Cucumber.(Cucumber.java:62)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:250)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:113)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

    Results :

    Tests in error:
    initializationError(se.thinkcode.itake.RunCukesTest): No features found at [classpath:se/thinkcode/itake]

    Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

    [INFO] ————————————————————————
    [INFO] BUILD FAILURE
    [INFO] ————————————————————————
    [INFO] Total time: 7.603s
    [INFO] Finished at: Wed Jun 04 13:06:08 BST 2014
    [INFO] Final Memory: 18M/157M
    [INFO] ————————————————————————
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.2:test (default-test) on project cucumberDemo1: There are test failures.
    [ERROR]
    [ERROR] Please refer to C:\Auto Framework_Krish\cucumberDemo1\target\surefire-reports for the individual test results.
    [ERROR] -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

    Comment by krish — June 4, 2014 @ 14:10

    • Hi!

      I know that my example runs. Are your sure that the feature file is in the right package in your resources directory? Your stack trace suggests that it can’t be found.

      You don’t have to define the features that should be executed in the runner class. Cucumber will use all feature files it finds on the classpath in the same package, or any subpackages, as the runner class.

      I would double check spelling of the resources directory as my first trouble shooting point to make sure I haven’t misspelled it and therefore not included the feature file in the classpath.

      HTH
      Thomas

      Comment by Thomas Sundberg — June 5, 2014 @ 06:58

  2. Thanks, Thomas. Your straightforward, stripped-down example clears things up immensely. -A

    Comment by afekete — June 23, 2014 @ 23:08

  3. Very useful introduction, thank you

    Comment by Danny — November 25, 2014 @ 09:46

  4. really useful thanks.. On 17 it fails ๐Ÿ™‚ for any number less than 42 it will fail ๐Ÿ˜‰

    Comment by Abhishek — December 18, 2014 @ 14:46

  5. My .feature file is not being found. When I run the junit test I get the following output

    No features found at [classpath:se]

    0 Scenarios
    0 Steps
    0m0.000s

    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.139 sec

    Results :

    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

    [INFO] ————————————————————————
    [INFO] BUILD SUCCESS
    [INFO] ————————————————————————
    [INFO] Total time: 5.816s
    [INFO] Finished at: Thu Jan 08 10:24:36 IST 2015
    [INFO] Final Memory: 5M/15M
    [INFO] ————————————————————————

    Comment by Harish — January 8, 2015 @ 05:56

    • Hi!

      It sounds to me that something is broken with your path so the feature files are not a part of the class path.

      I would start with checking the spelling of the resources directory. If you misspelled it, its will not be included in the class path and therefore not found by the Cucumber JUnit runner. Another possible problem could be that your misspelled the suffix on the feature file. It will not be picked up unless it is correct spelled.

      So, double check the directory structure, the spelling of the directories and the spelling of the suffixes for the feature files.

      HTH
      Thomas

      Comment by Thomas Sundberg — January 8, 2015 @ 06:58

  6. […] Thomas Sundberg has a few examples showing cucumber-jvmย in action. […]

    Pingback by Making acceptance testing easy, useful and fun with BDD – enter cucumber | Adventures outside the library — February 26, 2015 @ 12:25

  7. cucumber.runtime.CucumberException: Failed to instantiate class tests.SFDC.InsideSale.InsideSaleEndToEnd
    at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:40)
    at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:26)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:37)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:298)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:48)
    at cucumber.runtime.model.CucumberScenarioOutline.run(CucumberScenarioOutline.java:46)
    at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:163)
    at cucumber.api.testng.TestNGCucumberRunner.runCucumber(TestNGCucumberRunner.java:63)
    at cucumber.api.testng.AbstractTestNGCucumberTests.feature(AbstractTestNGCucumberTests.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:34)
    … 35 more
    Caused by: java.lang.ExceptionInInitializerError
    at salesforce.connections.ConnectionBase$connection.(ConnectionBase.java:13)
    at utils.pageobject.PageBase.(PageBase.java:9)
    at tests.SFDC.InsideSale.InsideSaleEndToEnd.(InsideSaleEndToEnd.java:23)
    … 40 more
    Caused by: java.lang.NullPointerException
    at java.util.Properties$LineReader.readLine(Properties.java:434)
    at java.util.Properties.load0(Properties.java:353)
    at java.util.Properties.load(Properties.java:341)
    at utils.common.ConfigPropertyProvider.accessConfigFile(ConfigPropertyProvider.java:28)
    at utils.common.ConfigPropertyProvider.(ConfigPropertyProvider.java:14)
    at salesforce.connections.ConnectionManagement.(ConnectionManagement.java:28)
    … 43 more

    ===============================================
    InsideSaleEndToEndTesting
    Total tests run: 1, Failures: 1, Skips: 0
    ===============================================

    I am seeing this error message.. I have provided correct path on –glue and –feature on test class. Still facing this issue. Can you please help me to solve this issue? Thanks!

    Comment by Umang Patel — February 24, 2016 @ 01:26

    • Hi!

      I would check why you get a NullPointerException in your class ConfigPropertyProvider at line 28.

      /Thomas

      Comment by Thomas Sundberg — February 24, 2016 @ 05:44

  8. This runs smoothly… ๐Ÿ™‚ those who are not able to run successfully, I would suggest to create a new maven project and copy paste all the files mentioned in this blog instead of using this stuff in existing project.

    Comment by Anil Mishra — September 21, 2016 @ 15:59

    • Hi!

      My idea is that this tutorial is not for patching an existing Cucumber setup, it is for creating a new one. The way to do that is to start fresh and do as you suggest, use these files as they are and get thing running. Then modify and understand what part does what.

      That is, you are emphasizing my idea.

      Thanks!
      thomas

      Comment by Thomas Sundberg — September 21, 2016 @ 20:22

  9. Is there any way to convert JSON cucumber to HTML like index.html or from json to report.js?

    Comment by shubham — November 15, 2016 @ 14:52

    • Hi!

      I don’t know of a tool that can convert a Cucumber json file to html.

      /Thomas

      Comment by Thomas Sundberg — November 16, 2016 @ 06:52

  10. Hi.. I have written code for Testruner, created a Feature file under feature folder and created stepdefination file as well,but it is throwing error at run time.Below is the error which i am getting:
    cucumber.runtime.CucumberException: Failed to instantiate public cucumber.runtime.java.JavaBackend(cucumber.runtime.io.ResourceLoader) with [cucumber.runtime.io.MultiLoader@3834d63f]
    at cucumber.runtime.Reflections.newInstance(Reflections.java:44)
    at cucumber.runtime.Reflections.instantiateSubclasses(Reflections.java:30)
    at cucumber.runtime.Runtime.loadBackends(Runtime.java:98)
    at cucumber.runtime.Runtime.(Runtime.java:65)
    at cucumber.api.junit.Cucumber.createRuntime(Cucumber.java:78)

    Details :
    1). Package : Cucumber ->test_Runner.java
    2). Package : stepdefination -> LoginTest.java
    3). Folder : Feature –> login.feature

    Please suggest what can be done to fix this. I have the updated dependencies of all the cucumber jars –> 1.2.5 version is the latest.

    Comment by QA_AB — March 6, 2017 @ 11:15

    • Hi!

      I suggest that ask this question at the Cucumber mailing list instead.

      /Thomas

      Comment by Thomas Sundberg — March 6, 2017 @ 17:42


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: