Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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 · 5 comments
Closed

CucumberException when running Cucumber with Jacoco code coverage #258

remast opened this issue Mar 14, 2012 · 5 comments

Comments

@remast
Copy link

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.

@aslakhellesoy
Copy link
Contributor

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
Copy link
Author

remast commented Mar 14, 2012

Sounds like a good solution.

@remast
Copy link
Author

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

@aslakhellesoy
Copy link
Contributor

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.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants