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

All active tests transformed from JUnit1-4 to Junit5 #23598

Merged
merged 69 commits into from
Sep 9, 2021

Conversation

dmatej
Copy link
Contributor

@dmatej dmatej commented Sep 9, 2021

Changes were limited to src/test directories and test-utils module.
Main changes:

  • hk2-runner was replaced by Hk2Junit5Extension and it's children
  • as a consequence, utils module was rewritten from the ground and finally renamed
  • many tests were reenabled and fixed
  • remaining disabled tests detected bugs or are not stable or have some external dependencies

Notes for reviewers

Please run the build including tests on your machine and report if it would fail - which module, which tests and don't forget to mention your system, JDK version and please, add stacktrace.

I am especially curious if there would not be any issues on Windows or Mac.

mvn clean install -Pstaging -T4C -Pjacoco

Tested on:

Kubuntu 20.10
Maven home: /home/dmatej/work/apache-maven-3.8.1
Java version: 17-ea, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-17-ea25-2522
Default locale: cs_CZ, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-63-generic", arch: "amd64", family: "unix"

- also moved "example" impl to own package and formatted definitions so now it
  makes a bit more sense (to me at least)
- also moved test example code and utilities to own package
…crazy stuff

- many tests were ignoring errors, so I removed catch blocks
- some tests were not closing resources
- some patrs are simply obsoleted and should be deleted
- some dead code was deleted
- this was just a quick visit, more work required to reach much better quality
…junit4

- and also doesn't swallow exceptions any more
- also deleted ProxyModule - wasn't used anywhere
- some tests were bit extended, some were deleted
- based on hk2-junitrunner
- portions of code were copy pasted as they are not public
- public classes were reused
- simplified own integration with tests respecting JUnit5 principles
- InteractiveTester should be transformed to real TestContainers test later.
…+ deleted zombies

- two test classes were commented out and not usable
- referred file doesn't exist any more
…of junit4 + enhanced

- one_probe.xml contained two probes and two_probe.xml just one
- test didn't test anything, just loaded files without exceptions
…l experience

- prepareAdminSubject - this heuristic didn't work and always ended in the block
  in the end of the method. That was moved to Utils.createInternalAsadminSubject.
  Somewhere in the progress I used it in the extension until I found better
  and more stable solution.
- HK2Extension now allows to use two own annotations
  - ExcludeClasses disables tries to create services of given classes
  - CustomConfiguration allows to use given domain.xml file for test
- important to have the best possible information about the failure
…led and fixed tests

- lesson: whatever you will annotate with @service will be discovered
- lesson: whatever annotated with @secure cannot be instantiated in tests
- lesson: @secured services can be mocked
- resolution: ConfigApiTest must die, HK2Junit5Extension must be extensible
  to allow customizations for the module (own dependencies)
- tests were enabled, fixed and extended, I hope they are stable enough
- mocks and examples were moved to the package based on the name of the module
- several classes in tests removed, because they weren't used.
- DomainTest.xml was updated - based on real domain.xml from current
  GlassFish 6.2.1

Signed-off-by: David Matějček <dmatej@seznam.cz>
…junit4

- DefaultGUICallbackHandlerTest can be executed in Eclipse, depends on AWT UI
- several tests enabled
- AppClientContainerTest deleted, depended on unknown classes and was commented out
- ServerEnvironmentImpl is extremely problematic class as it's initialization
  is not well defined, but the class changes System.properties and affects
  whatever uses them later (but doesn't affect what started earlier)
- added FIXME for ServerEnvironment, see issue eclipse-ee4j#23593 on GitHub
- resolved cyclic dependencies and side effects (at least partially, so now
  tests pass in maven
- Replaced by the Junit5 extension
- also fixed several tests which never did cleanup
- moved methods and classes
- remains of Utils were renamed to ReflectionUtils as it is the only thing left
- ReflectionUtils replaced mockit.Deencapsulation, which was removed from
  jmockit as a bad practice. Same applies here, the less you will use it, the
  better code you have. But in GF case there are few places which cannot be
  tested in better way now. Yet.
@Inject
private StartupContext startupContext;

// FIXME: Workaround, because ServerEnvironmentImpl changes global System.properties, but other services
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on this I created this issue: #23593

- formatting
- trivialities
- renamed AppTest to JavaEETransactionManagerTest (it tests behavior of the class)
@dmatej dmatej marked this pull request as ready for review September 9, 2021 15:21
@pzygielo
Copy link
Contributor

pzygielo commented Sep 9, 2021

Passed with no problem on

Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: /usr/local/maven
Java version: 11.0.11, vendor: Oracle Corporation, runtime: /usr/local/jdk-11.0.11+9
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "5.13.14-200.fc34.x86_64", arch: "amd64", family: "unix"

I've only checked that in code just tests were modified, and that junit4 was removed from nucleus/parent.

Copy link
Contributor

@arjantijms arjantijms left a comment

Choose a reason for hiding this comment

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

Amazing work! Just checked that it passed and glanced over the code. Looks good!

@arjantijms arjantijms merged commit be4fce4 into eclipse-ee4j:master Sep 9, 2021
@arjantijms
Copy link
Contributor

Forgot to post the versions:

Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: /usr/local/Cellar/maven/3.8.2/libexec
Java version: 17-ea, vendor: Oracle Corporation, runtime: /Users/arjan/.sdkman/candidates/java/17.ea.33-open
Default locale: en_NL, platform encoding: UTF-8
OS name: "mac os x", version: "11.5", arch: "x86_64", family: "Mac"

@dmatej dmatej deleted the junit5 branch September 13, 2022 05:49
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.

3 participants