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

Eclipse Oxygen requires AspectJ to run JUnit tests #56

Open
guy-rouillier opened this issue May 16, 2018 · 8 comments
Open

Eclipse Oxygen requires AspectJ to run JUnit tests #56

guy-rouillier opened this issue May 16, 2018 · 8 comments

Comments

@guy-rouillier
Copy link

I just upgraded to Eclipse Oxygen. I had been running velocity-scripting successfully under Neon. When I imported the project to Neon and tried to run a unit test in VelocityLanguageTest, I kept getting initialization errors, which were simply reported as FilterRequest errors. Here's a bug report about FilterRequest hiding the actual problem:

junit-team/junit4#1277

Using the suggested workaround of running JUnit against the file instead of a single test, I discovered that the stack trace was claiming ClassNotFound on AspectJ. So, I added an AspectJ dependency in pom.xml, and that fixed the issue.

I do have AspectJ in Eclipse, but that does not help.

@hazendaz
Copy link
Member

@guy-rouillier Is this still an issue with latest eclipse 2018-12?

@guy-rouillier
Copy link
Author

guy-rouillier commented Dec 28, 2018

Here's what I've discovered in Eclipse 2018-12. With the changes to the velocity-scripting to JUnit 5, I can no longer easily rerun this test in Eclipse Oxygen. See:

https://stackoverflow.com/questions/46717693/eclipse-no-tests-found-using-junit-5-caused-by-noclassdeffounderror

So, in 2018-12, I discovered that if I run the tests with the included pom.xml, i.e., with the MyBatis JAR included via Maven, the tests complete successfully.

However, I normally develop using a linked MyBatis base project, so that I have the full MyBatis source available to me. When I try to run the JUnit tests this way, the tests do not run. I simply get a popup with the following:

Title: Could not run test
Body: No tests found with test runner 'JUnit 5'.

I'm suspecting a clash between the JARs in the MyBatis project, and the JARs in the velocity-scripting project. However, I modified the MyBatis project so that it does not export any JARs to dependent projects, and I still get the same error.

My former solution of adding aspectjrt-1.9.1.jar to the Maven pom.xml is not working in Eclipse 2018-12.

[Update] I switched to tag 3.4.6 in the MyBatis project (instead of head), since that corresponds with the version of the MyBatis JAR included in the velocity-scripting project. Unfortunately, results are unchanged.

@hazendaz
Copy link
Member

@guy-rouillier Eclipse Oxygen didn't really support junit 5 well. It was released in 2017 prior to junit 5 being completed. While support was there it was weak and wasn't full until service pack 3. With Photon, full support was there but had bugs. With Eclipse 2018-09 it had issues as well later fixed by 2018-12. All of the issues were easily worked around so Eclipse didn't make any fixes a priority. I'm using 2018-12 now and not experiencing any issues at all.

What exactly does your layout look like as there shouldn't be any cross over between your project and this one. Just because you depend on another project by it being included in your workspace, unit tests of one do not affect the other. I think that is a pretty typical use case and I've had a lot of experience with junit 5 at this point to not see how that is even remotely possible unless you embedded the source code directly into your source tree in some way. Can you provide a layout usage that you are using in Eclipse?

@guy-rouillier
Copy link
Author

Sure. I have the mybatis-3 project (https://github.com/mybatis/mybatis-3) imported as a Maven project into Eclipse, and built.

I then have the velocity-scripting project (https://github.com/mybatis/velocity-scripting) also imported as a Maven project. As I said previously, if I don't alter anything in the pom.xml for velocity-scripting (so that it uses mybatis-x.x.x.jar from Maven) within Eclipse, I can open up file src/test/java/org/mybatis/scripting/velocity/use/VelocityLanguageTest.java and successfully run unit tests. For example:

  1. Scroll double and double click "testDynamicSelectWithPropertyParams" to select it, then right click, Run As, JUnit Test. The test will complete successfully. I've modified the test slightly to print some results to make debugging easier:

log.info("testDynamicSelectWithPropertyParams name : " + n.getFirstName() + " " + n.getLastName());
Good so far. Now, as I mentioned, during development, rather than simply use the mybatis-x.x.x.jar from Maven, which of course gives you no insight into the source code, I prefer to use the mybatis project, which I've already imported and built in Eclipse. You can accomplish this several ways. The easiest is simply to open the MyBatis project. As long as you use the version mentioned in the pom.xml for velocity-scripting. Eclipse will automatically find it, and since the dependency has been satisfied, will not retrieve the JAR from Maven. You can actually observe this in action: as soon as you open the MyBatis project, the mybatis-x.x.x.jar will disappear from the Maven Dependencies list, and a mybatis folder will be added to Maven Dependencies, showing that Maven is now using the MyBatis project to fulfill that dependency.

Another way to accomplish the same thing is to comment out the Maven dependency for the mybatis-x.x.x.jar in the velocity-scripting pom.xml, and in Eclipse, add a project dependency on the MyBatis project via right click on the velocity-scripting project, select Build Path - Configure Build Path, and on the Project tab, click the Add... button and check the checkbox for the mybatis project.

These 2 methods are equivalent. I prefer the first method because it is less work. Using either method, when I now right click on the JUnit test VelocityLanguageTest.testDynamicSelectWithPropertyParams(), and again select Run As, JUnit Test, instead of completing successfully, Eclipse simply displays a popup message box with the following:

Title: Could not run test
Body: No tests found with test runner 'JUnit 5'.

Hopefully I've fully explained the development environment. Having one project depending on another is standard practice in Eclipse, and normally works without issue, so I'm perplexed why this is failing.

Thanks.

@hazendaz
Copy link
Member

hazendaz commented Dec 29, 2018 via email

@guy-rouillier
Copy link
Author

guy-rouillier commented Dec 29, 2018

Just a FYI, don't know if this will help or just make for more confusion. I'm working on a Groovy scripting engine for MyBatis. I've borrowed from the Velocity and FreeMarker scripting engines to help me along. I have the exact same JUnit tests in the Groovy project that Velocity has. Using the same MyBatis base project for both, the JUnit test that is failing for Velocity works in Groovy. Here are screenshots of the Maven dependencies for both projects. The only differences I see are the JARs needed for each language. So, the fact that the Groovy project works with the base MyBatis project would appear to indicate that the problem is not with the base MyBatis project. At this point, I'm very confused.

But my main concern is the Groovy scripting engine, and thankfully that's working. :).

Groovy
groovy_project_libs

Velocity
velocity_project_libs

@hazendaz
Copy link
Member

hazendaz commented Jan 9, 2019

@guy-rouillier We actually moved mybatis-3 onto junit 5 entirely now. Can you see if re-sync of the latest master there still runs into similar issues? I've had issues with junit 5 in various scenerios now that should work on intellij and eclipse in other projects as well as a few of these in different scenerios. I'm still going to use your great documentation of the issue here for further testing but think we might have overcome the issue for you. Let me know! Thanks!

@guy-rouillier
Copy link
Author

guy-rouillier commented Jan 10, 2019

I updated both mybatis3 and velocity-scripting projects. Unfortunately, I'm still seeing the same behavior I reported in this comment. Let me know if I can test anything else. Thanks for looking into this.

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

No branches or pull requests

2 participants