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

NETBEANS-1744: Support Run/Debug Focused Test Method for @Nested JUni… #1069

Closed
wants to merge 1 commit into from

Conversation

srdo
Copy link
Contributor

@srdo srdo commented Jan 2, 2019

…t 5 test classes in Maven projects

The reason this doesn't work currently is that Netbeans assumes all test methods are in the top level class in a file. For @Nested tests, the tests are in an inner class.

The changes here make Netbeans use the immediately enclosing class instead of the top level class when doing run/debug for Maven projects.

Note that this only fixes run/debug for single test methods. Running @Nested classes is broken in Surefire junit-team/junit5#1343.

@geertjanw
Copy link
Member

Thanks for this PR. I'm not familiar enough with this to be able to review it, how confident are you of this, what problems do you anticipate?

@srdo
Copy link
Contributor Author

srdo commented Jan 18, 2019

I'm reasonably confident in this. I've checked that test single works for @Nested tests, and also for normal JUnit 5 and 4 tests.

There shouldn't be a change in behavior for non-Maven projects, since the changes outside the Maven module should be backwards compatible.

I think the only slight oddity I would expect from the new handling is that running single nested tests will work even if you don't mark the class as @Nested, but I don't feel like that's really a problem.

@geertjanw
Copy link
Member

OK. If we merge this and issues occur or further problems arise, will you be around to work on that?

@srdo
Copy link
Contributor Author

srdo commented Jan 18, 2019

Most likely yes, but I'd rather not commit to anything. If the patch turns out to cause trouble, you can always revert it. Waiting for more reviewers is also an option, I'm not under time pressure to get this in.

Copy link

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added few comments/opinions how to make your donation better. One of them is marked as request - that one has to (in my opinion) be done before integration.

* @exception java.lang.IllegalArgumentException
* if the file or method name is {@code null}
*/
public SingleMethod(FileObject file, String binaryClassName, String methodName) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in API should be reflected in apichanges.xml, version of the module should be incremented in manifest.mf or project properties. New elements should have @since tag. Plus: all modules that depend on the new elements should depend on the new version of the API module.

This is a request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will fix


* @return Class name held by this object
*/
public Optional<String> getBinaryClassName() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer plain String that can be null. There is no Optional in this API yet, and there is no real reason to start with it as far as I can tell.

This is an opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plain nullable String makes it more likely that users of this method will forget to null check the return value. Using Optional means that users don't have to read and remember the Javadoc (or code) of each method, in order to tell whether they need to null check.

I would prefer not to change it, but if you feel strongly that Optional is not useful, I will change this to plain String.

@@ -91,6 +92,23 @@ public void run(CompilationController controller) throws Exception {
}
}
}
if (methodName != null) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code change should be covered by unit test. Especially when you cannot commit to future maintenance of the code, do others a favour and cover your code with tests.

This is an opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Are there any tests of similar code in the codebase I could use for reference? I think deep stubbing CompilationController in order to test this would make for a brittle test.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JaroslavTulach are there examples of similar code being tested in the codebase, without deep stubbing the CompilationController?

@@ -144,6 +159,24 @@ public void run(CompilationController compilationController) throws Exception {
UIJavaUtils.openFile(fo2open[0], (int) line[0]);
}
}

private Element findInnermostTypeElement(Element containingTypeElement, List<? extends String> targetInnerClassNames) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code also deserves a test. See above for justification...

This is an opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'm not sure how to test this, since this class is glued to some static methods. I'll take a look, but if you could point to a test of similar code elsewhere, it would be helpful.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JaroslavTulach are there tests of similar code that could be used as a starting point for testing this code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to stub CompilationController: refactor code to have the tested part callable and save make accessors so the test can collect the computed data. I.e. make the UserTask a package-private member class, so the test can instantiate it. Create sources in test data, then process it using JavaSource.parse(). Call the tested code with (real) CompilationController instance and observe the outcome.

@ixM
Copy link

ixM commented Dec 8, 2020

Hi,

Is there any plan to integrate this patch? It's still not working at the moment and Nested test classes are a big part of our testing plateform. It would really be amazing if it could be supported properly in Netbeans!

Thanks!

@srdo
Copy link
Contributor Author

srdo commented Dec 8, 2020

@ixM I'm not working on this, but you are welcome to take this over. You could probably fairly easily address the comments that were made on this PR. I think it might be integrated then?

@JaroslavTulach
Copy link

Yes, the PR can be integrated, if somebody polishes it. Closing for now when @srdo gave up. Make a change and reopen whoever takes over.

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

Successfully merging this pull request may close these issues.

None yet

7 participants