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
Updated CategoryFilter to prevent NPE with Cucumber and JUnit Categories #1511
Updated CategoryFilter to prevent NPE with Cucumber and JUnit Categories #1511
Conversation
- NullPointerException was being thrown if JUnit Categories were used in a project containing Cucumber tests. - Ensure CategoryFilter does not call createSuiteDescription if the description test class is null - Added integration test to reproduce the error
|
||
test { | ||
useJUnit { | ||
excludeCategories 'CategoryA' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the relevance of this category if it is excluded anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CategoryFilter
, the source of the bug, is only invoked if a category inclusion / exclusion is specified here. It doesn't matter what is excluded. In fact, no test is even annotated with this category.
public class DescriptionWithNullClassTest { | ||
|
||
@Test | ||
public void someTest() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't need to throw an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
@Test | ||
public void someTest() throws Exception { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the unnecessary new lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -64,4 +64,16 @@ public class JUnitCategoriesIntegrationSpec extends AbstractIntegrationSpec { | |||
def result = new DefaultTestExecutionResult(testDirectory) | |||
result.testClass("org.gradle.SomeTest").assertTestFailed("initializationError", startsWith("org.gradle.api.GradleException: JUnit Categories defined but declared JUnit version does not support Categories.")) | |||
} | |||
|
|||
def supportsCategoriesAndNullTestClassDescription() { | |||
when: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please a new line between when
and then
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
run "test" | ||
then: | ||
":test" in nonSkippedTasks | ||
and: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the last and
statement. It's OK to just have this under then
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thanks for the pull request. It has been merged! |
Awesome, thanks! |
Sure thing. Sorry about the long wait. |
Fix for #1510
This bug was originally reported by @krosenvold on the Gradle Forum.
Any of the checked boxes below indicate that I took action:
./gradlew quickCheck
For all non-trivial changes that modify the behavior or public API:
the forum or can reference a JIRA issue.
brief but explains the use case or problem you are trying to solve,
touches on the planned implementation approach as well as the test cases
that verify the behavior. Optimally, design documents should be submitted
as a separate pull request. Samples
can be found in the Gradle GitHub repository. Please let us know if you need help with
creating the design document. We are happy to help!
test coverage to verify the behavior. Before submitting the pull request
I ran a build on my local machine via the command
./gradlew quickCheck <impacted-subproject>:check
.DSL reference and Javadocs where applicable.