Forum Discussion

s-glatshtein's avatar
s-glatshtein
New Contributor
4 years ago

Running cucumber tests from external jar

Hello!
I'm trying to package my cucumber tests and run them using a small java program. I annotate the test class with `@CucumberOptions` and i run the class using JUnitCore. It works pretty well, but only with specific configurations:

 

  • If the feature is either "classpath:file.feature" or under a folder such as "somefolder/file.feature". It doesn't work if i put the feature file in the root or in a resource folder
  • If the step definitions class has a package anypackage in the start. This doesn't work when there's no package.

I've attached the runner class that works as a sample. I use a custom tool to report my tests to an external platform.

I want to make it work regardless of how we define the feature and glue in the runnable class. Anyone has any idea how?

3 Replies

  • Nishimura031's avatar
    Nishimura031
    Occasional Visitor

    two steps, you should be able to execute Cucumber from your own executable jar wherever you are able to execute a jar at all. Notice that you are mixing library version for Cucumber in your pom. I would use the latest version of all libraries. Compare cucumber-java , cucumber-testng and cucumber-junit.

    • s-glatshtein's avatar
      s-glatshtein
      New Contributor

      About the first part, what do you mean that the jar should be executable? I am running the test class using JUnitCore class, not with CLI.

      About the second part, I am using build.gradle and all the latest dependencies for all (or what was the latest). Here's the depedencies i use in my runner program:

       

      dependencies {
      // https://mvnrepository.com/artifact/org.testng/testng
      // implementation group: 'org.testng', name: 'testng', version: '7.3.0'

      implementation group: 'junit', name: 'junit', version: '4.12'
      compile group: 'org.testng', name: 'testng', version: '7.3.0'
      // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine
      implementation group: 'io.cucumber', name: 'cucumber-java', version: '6.10.0'
      implementation group: 'io.cucumber', name: 'cucumber-junit', version: '6.10.0'
      implementation group: 'io.cucumber', name: 'cucumber-testng', version: '6.10.0'
      // https://mvnrepository.com/artifact/org.junit.platform/junit-platform-launcher
      implementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.7.0'
      }

       

      • s-glatshtein's avatar
        s-glatshtein
        New Contributor

        Anyone has any ideas? How can i use cucumber with these CucumberOptions?