Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

CucumberException when running Cucumber with Jacoco code coverage #258

Closed
remast opened this Issue Mar 14, 2012 · 4 comments

Comments

Projects
None yet
2 participants

remast commented Mar 14, 2012

Hi,

running cucumber tests with Jacoco code coverage enabled causes a cucumber exception.

Cause of this exception:
The Jacoco code coverage introduces new methods in the class using byte code manipulation. This then causes the following assertion to throw a cucumber exception:

private void assertNoDeclaredMethods(Class clazz) {
    if (clazz.getDeclaredMethods().length != 0) {
        throw new CucumberException(
                "\n\n" +
                        "Classes annotated with @RunWith(Cucumber.class) must not define any methods.\n" +
                        "Their sole purpose is to serve as an entry point for JUnit.\n" +
                        "Step Definitions should be defined in their own classes.\n" +
                        "This allows them to be reused across features.\n" +
                        "Offending class: " + clazz + "\n"
        );
    }
}

I suggest to change this code so that a warning is logged instead of throwing an exception. After all even if methods are declared in that class it does not do much harm.

Owner

aslakhellesoy commented Mar 14, 2012

The main reason for this exception to be thrown is to prevent people from adding step definitions in the class. We could relax the check to only raise if there are stepdef methods.

This might be a little tricky since the cucumber-junit module doesn't depend on the cucumber-java module, where the stepdef annotations are, so we might have to use reflection here.

remast commented Mar 14, 2012

Sounds like a good solution.

remast commented Mar 19, 2012

I just made the change we agreed on. The changes were made in our fork so I am not sure how you can fetch that easily. As the changes are minor maybe just grab that by copy-and-paste.

Here's the commit: https://github.com/PE-INTERNATIONAL/cucumber-jvm/commit/0caed66960af64d298b3f2a7af57e8146db35ed3

Owner

aslakhellesoy commented Mar 20, 2012

Ok, I cherry-picked that commit and made some minor changes.

Please keep separate branches for unrelated fixes to make it easier for me to pick contributions independently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment