[JVM] Exception thrown when no tags are found

703 views
Skip to first unread message

Darrell

unread,
Jul 27, 2012, 4:23:45 AM7/27/12
to cu...@googlegroups.com
Hi

I'm working with an automated testing environment using ANT and Cucumber-JVM. The problem I'm facing is that we have two systems where we may need to run features against, some features are for landscape1 and some features for landscape2. I was going to use tags to define which scenario is for which landscape, however some features may not necessarily contain a scenario for both landscapes. This proves to be a problem when running cucumber with -tags @landscape1 if there are no scenarios defined then an exception is thrown

[java] cucumber.runtime.CucumberException: None of the features at [build/test-classes, src/test/resources] matched the filters: [@landscape1]
[java] at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:45)
     [java] at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:98)
     [java] at cucumber.runtime.Runtime.run(Runtime.java:82)
     [java] at cucumber.cli.Main.run(Main.java:20)
     [java] at cucumber.cli.Main.main(Main.java:12)
     [java] Running Shutdown Hook...
     [java] Running Shutdown Hook executed!

I was wondering if there was any method of telling cucumber not to throw the exception if no tags are found, or performing an initial check to see whether any tags exist first and if they exist run cucumber, if not then skip that feature file..

I hope that makes sense

Darrell

Aslak Hellesøy

unread,
Jul 27, 2012, 6:11:19 AM7/27/12
to cu...@googlegroups.com
I added this failure mode to help people who screw up their commanx line options, giving them a hint why no features were run.

Removing this might help you, but do a disservice to many others.

What do people think?

Aslak

I hope that makes sense

Darrell

--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
 
 

Rob Park

unread,
Jul 27, 2012, 9:57:07 AM7/27/12
to cu...@googlegroups.com
On Fri, Jul 27, 2012 at 4:11 AM, Aslak Hellesøy <aslak.h...@gmail.com> wrote:




On 27 Jul 2012, at 09:23, Darrell <darrell.me...@sap.com> wrote:

Hi

I'm working with an automated testing environment using ANT and Cucumber-JVM. The problem I'm facing is that we have two systems where we may need to run features against, some features are for landscape1 and some features for landscape2. I was going to use tags to define which scenario is for which landscape, however some features may not necessarily contain a scenario for both landscapes. This proves to be a problem when running cucumber with -tags @landscape1 if there are no scenarios defined then an exception is thrown

[java] cucumber.runtime.CucumberException: None of the features at [build/test-classes, src/test/resources] matched the filters: [@landscape1]
[java] at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:45)
     [java] at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:98)
     [java] at cucumber.runtime.Runtime.run(Runtime.java:82)
     [java] at cucumber.cli.Main.run(Main.java:20)
     [java] at cucumber.cli.Main.main(Main.java:12)
     [java] Running Shutdown Hook...
     [java] Running Shutdown Hook executed!

I was wondering if there was any method of telling cucumber not to throw the exception if no tags are found, or performing an initial check to see whether any tags exist first and if they exist run cucumber, if not then skip that feature file..


I added this failure mode to help people who screw up their commanx line options, giving them a hint why no features were run.

Removing this might help you, but do a disservice to many others.

What do people think?

I think the same results as in Ruby makes the most sense to me.

0 scenarios
0 steps
0m0.000s

Feedback of 0's is pretty good information.
It doesn't necessarily "feel" like an exception to me, so I'd rather not get a stack trace there. 

//rob 

Aslak Hellesøy

unread,
Jul 27, 2012, 10:02:00 AM7/27/12
to cu...@googlegroups.com




On 27 Jul 2012, at 14:57, Rob Park <robert...@gmail.com> wrote:



On Fri, Jul 27, 2012 at 4:11 AM, Aslak Hellesøy <aslak.h...@gmail.com> wrote:




On 27 Jul 2012, at 09:23, Darrell <darrell.me...@sap.com> wrote:

Hi

I'm working with an automated testing environment using ANT and Cucumber-JVM. The problem I'm facing is that we have two systems where we may need to run features against, some features are for landscape1 and some features for landscape2. I was going to use tags to define which scenario is for which landscape, however some features may not necessarily contain a scenario for both landscapes. This proves to be a problem when running cucumber with -tags @landscape1 if there are no scenarios defined then an exception is thrown

[java] cucumber.runtime.CucumberException: None of the features at [build/test-classes, src/test/resources] matched the filters: [@landscape1]
[java] at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:45)
     [java] at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:98)
     [java] at cucumber.runtime.Runtime.run(Runtime.java:82)
     [java] at cucumber.cli.Main.run(Main.java:20)
     [java] at cucumber.cli.Main.main(Main.java:12)
     [java] Running Shutdown Hook...
     [java] Running Shutdown Hook executed!

I was wondering if there was any method of telling cucumber not to throw the exception if no tags are found, or performing an initial check to see whether any tags exist first and if they exist run cucumber, if not then skip that feature file..


I added this failure mode to help people who screw up their commanx line options, giving them a hint why no features were run.

Removing this might help you, but do a disservice to many others.

What do people think?

I think the same results as in Ruby makes the most sense to me.

0 scenarios
0 steps
0m0.000s

Feedback of 0's is pretty good information.
It doesn't necessarily "feel" like an exception to me, so I'd rather not get a stack trace there. 


Ok. Darrell, can you create a ticket please?

Aslak

Дмитрий Бережной

unread,
Jul 30, 2013, 6:01:47 AM7/30/13
to cu...@googlegroups.com
Not sure if problem is actual a year ago, but I've faced with that problem some time ago and solved it using custom runner:
package cucumber.hackedrunner;

import cucumber.api.cli.Main;
import cucumber.runtime.CucumberException;
import cucumber.runtime.Runtime;
import cucumber.runtime.RuntimeOptions;
import cucumber.runtime.io.MultiLoader;

import java.io.IOException;

public class HackedRunner extends Main {

    public static void main(String[] argv) throws Throwable {
        run(argv, Thread.currentThread().getContextClassLoader());
    }

    public static void run(String[] argv, ClassLoader classLoader) throws IOException {
        RuntimeOptions runtimeOptions = new RuntimeOptions(System.getProperties(), argv);

        cucumber.runtime.Runtime runtime = new Runtime(new MultiLoader(classLoader), classLoader, runtimeOptions) {
            @Override
            public void run() {
                try {
                    super.run();
                } catch (CucumberException e) {
                    if (e.getMessage().contains("None of the features")) {
                        System.err.println(e.getMessage());
                    } else {
                        throw e;
                    }
                }
            }
        };
        runtime.writeStepdefsJson();
        runtime.run();
        System.exit(runtime.exitStatus());
    }
}


So you just need to override Runtime.run() method to handle this.
Then you can use this class instead cucumber.api.cli.Main when running Cucumber features from console :)

David Kowis

unread,
Aug 2, 2013, 11:30:17 AM8/2/13
to cu...@googlegroups.com


On Friday, July 27, 2012 5:11:19 AM UTC-5, Aslak Hellesøy wrote:




On 27 Jul 2012, at 09:23, Darrell <darrell.me...@sap.com> wrote:

Hi

I'm working with an automated testing environment using ANT and Cucumber-JVM. The problem I'm facing is that we have two systems where we may need to run features against, some features are for landscape1 and some features for landscape2. I was going to use tags to define which scenario is for which landscape, however some features may not necessarily contain a scenario for both landscapes. This proves to be a problem when running cucumber with -tags @landscape1 if there are no scenarios defined then an exception is thrown

[java] cucumber.runtime.CucumberException: None of the features at [build/test-classes, src/test/resources] matched the filters: [@landscape1]
[java] at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:45)
     [java] at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:98)
     [java] at cucumber.runtime.Runtime.run(Runtime.java:82)
     [java] at cucumber.cli.Main.run(Main.java:20)
     [java] at cucumber.cli.Main.main(Main.java:12)
     [java] Running Shutdown Hook...
     [java] Running Shutdown Hook executed!

I was wondering if there was any method of telling cucumber not to throw the exception if no tags are found, or performing an initial check to see whether any tags exist first and if they exist run cucumber, if not then skip that feature file..


I added this failure mode to help people who screw up their commanx line options, giving them a hint why no features were run.

Removing this might help you, but do a disservice to many others.

What do people think?

I don't think it's that big of a deal. If any change is to be made, maybe it shouldn't throw a stack trace, but it should still exit 1. Not running any tests, unless explicitly dictated using say, --wip, should fail. The whole point of having Continuous Integration is to continuously run those tests, if suddenly they stop being executed, you should find out about it.

I don't mind the exception, but I can understand desiring it to be cleaner.
--
David

Björn Rasmusson

unread,
Aug 2, 2013, 12:02:02 PM8/2/13
to cu...@googlegroups.com

Hi,

I have developed PR https://github.com/cucumber/cucumber-jvm/pull/567 in response to this discussion (the change works well with a use case with Cucumber-JVM and Jenkins I have in mind).

Cucumber-JVM will return exit code 0 when no tags are found, or no features at all are found, but the message currently use in the exception will still be printed ("None of the features at ..."). It may be helpful in some cases, and it is only one extra printed line before the:
0 scenarios
0 steps
0m0.000s

A change in the JUnitFormatter is also made to add a dummy testcase element in this situation, when no features to be executed are found. This is because Jenkins will mark the job as failed even if the exit code is 0, if the generated JUnit report contains no testcase element at all (http://jenkins-ci.361315.n4.nabble.com/Jenkins-fails-if-there-are-no-testcases-td3899185.html).

In a situation when you have a Jenkins job for the features tagged for the current iteration (and use JUnit report for Jenkins to parse). I do not think that job should fail, if in the shift between iteration there temporarily are no features with that tag.

Regards
Björn
Reply all
Reply to author
Forward
0 new messages