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

Tests requiring AssertJ Swing as a Maven dependency encounter a NoClassDefFoundError under Pit #881

Open
ben-clegg opened this issue Apr 17, 2021 · 5 comments

Comments

@ben-clegg
Copy link

I have some JUnit tests for my Swing GUI using AssertJ-Swing, which work fine under other Maven test goals, but they crash out when running Pit. In addition, my other (non-AssertJ) tests work fine with Pit.
This issue occurs for both OpenJDK 11 and OpenJDK 8.

The exact issue I am facing is that a java.lang.NoClassDefFoundError is thrown when running any AssertJSwingJUnitTestCase, when it tries to access org.assertj.swing.core.BasicRobot.

I have all of my testing dependencies included in my pom.xml, under the test scope.
I have also tried explicitly including AssertJ JAR as additional classpath elements.
I've uploaded a gist of my pom.xml here: https://gist.github.com/ben-clegg/c73660b2cdbc82d01dbdcd038fd23adb

Since this works fine with other Maven goals, I believe this is an issue with Pit.
Does Pit have similar issues with other Maven dependencies, or is this unique to AssertJ?
Can you suggest any workarounds?

Thanks

@StefanPenndorf
Copy link
Contributor

Hi @ben-clegg

Could you provide the full stack trace of the NoClassDefFoundError?

Pitest uses -Djava.awt.headless=true to prevent stealing focus on Mac (see #581). This might interfere with GUI-testing.

@ben-clegg
Copy link
Author

Hi Stefan,

Thanks for the reply. Here are the logs with the headless setting enabled and disabled, the issue seems to occur with or without this setting. In case it helps, I'm using Linux.

Default : https://gist.github.com/ben-clegg/975ffbd09e0850e2b0208884e308d7ab
No Headless : https://gist.github.com/ben-clegg/3a1875904115aabfde2f60be15e41fd4

Thanks

@StefanPenndorf
Copy link
Contributor

As your stacktraces tell HeadlessGraphicsEnvironment will be used which fails with HeadlessException in either gist. You cannot disable headless for test minions due to #581 .

The change merged in #601 adds -Djava.awt.headless=true to every mutation minion created. There is only the option to add further settings but not to remove the default.

So far so good. The problems seems the new default introduced in #601 .

@hcoles
What do you think would be the best solution: Remove the default and warn Mac users that they should add -Djava.awt.headless=true themselves or should one introduce another configuration option that lets one turn headless on/off ?

@jzy3d
Copy link

jzy3d commented Jun 16, 2022

To my opinion, it would be nice to get a suggestion for the CLI when a headless exception is thrown. I spent little time to figure out where the problem came from (I dropped the solution here for others).

@hcoles
Copy link
Owner

hcoles commented Jul 14, 2022

This will work differently in pitest 1.9.3. once #1054 is merged.

Auto adding of the jvm arg can be disabled with -Dfeatures="-macos_focus"

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

4 participants