Skip to content

Running cucumber tests in Eclipse causes exception #259

remast opened this Issue Mar 14, 2012 · 3 comments

2 participants

remast commented Mar 14, 2012

Running cucumber tests in eclipse causes an exception because the *.feature files exist duplicated in the classpath. Eclipse puts all resources including the *.feature files in the classpath. Additionally the classpath contains the directory with the resources.
-> As a result two identical versions of the same *.feature files exist in the classpath.

This causes the following code in the FeatureBuilder to throw a CucumberException:

public void parse(Resource resource, List<Object> filters) {
    Formatter formatter = this;
    if (!filters.isEmpty()) {
        formatter = new FilterFormatter(this, filters);
    Parser parser = new Parser(formatter);
    String gherkin = read(resource);

    String checksum = checksum(gherkin);
    String path = pathsByChecksum.get(checksum);
    if (path != null) {
        throw new CucumberException(String.format("Found the same source in %s and %s", path, resource.getPath()));
    pathsByChecksum.put(checksum, resource.getPath());

Having two identical *.feature files on the claspath does no harm. So I suggest that's tolerated as long as both files have the same checksum. If desired a warning could be logged.

Cucumber member

That code was written to fix #165.

Is eclipse copying .feature files from a source directory to a target directory? Why? If so, why are both the source and target directories on the classpath?

How do you suggest fixing this issue without breaking the fix for #165?

remast commented Mar 14, 2012

Why eclipse does that I have no clue. What I know is that given I have a maven project in eclipse with the directory layout:

  • src/test/resources which contains the *.feature files and is a source directory of the project
  • target/classes as directory where eclipse puts the compiled classes (and all resources including *.feature files) In that setting I end up with two identical feature files in the classpath.

For fixing #165 the md5 checksum was introduced. But can't we just ignore multiple feature files having the identical md5 checksum? So if there are 2 feature files on the classpath with identical md5 checksum only one of them is executed. If there are two feature files on the classpath having different md5 checksums a CucumberException is thrown. If I got it right this would not break #165.

Cucumber member

@remast that sounds like a good approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.