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

Adds JUnit 5 test support #3322

Merged
merged 1 commit into from Aug 2, 2021
Merged

Adds JUnit 5 test support #3322

merged 1 commit into from Aug 2, 2021

Conversation

reinhapa
Copy link
Member

Implements the #3321 feature.

@dizzzz dizzzz requested a review from adamretter March 25, 2020 19:54
@dizzzz
Copy link
Member

dizzzz commented Mar 25, 2020

rerunning tests as in travis all tests failed.

Copy link
Member

@dizzzz dizzzz left a comment

Choose a reason for hiding this comment

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

LGTM, now lets convince travis

@reinhapa
Copy link
Member Author

@dizzzz I got some trouble getting the problem that travis seems to have while building... :-(

@dizzzz
Copy link
Member

dizzzz commented Mar 26, 2020

appveyor and travis are consistent, interestingly:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.2:analyze-only (analyze) on project exist-ant: Dependency problems found -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :exist-ant
Command exited with code 1
Running "on_failure" scripts

@dizzzz
Copy link
Member

dizzzz commented Mar 26, 2020

image

https://www.baeldung.com/junit-5-migration

<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <version>${junit5.vintage.version}</version>
    <scope>test</scope>
</dependency>

is missing for the sub-pomfiles?

(sorry for closing)

@dizzzz dizzzz closed this Mar 26, 2020
@dizzzz dizzzz reopened this Mar 26, 2020
@adamretter adamretter added the in progress Issue is actively being worked upon label Mar 26, 2020
@dizzzz
Copy link
Member

dizzzz commented Mar 28, 2020

hmmm
image

@adamretter
Copy link
Member

adamretter commented Mar 28, 2020

I took a look into this PR this morning and tried a few things. Unfortunately it is not a straight-forward thing to move eXist-db to Junit 5, for three reasons:

  1. We use JUnit rules for starting and stopping the eXist-db server for tests. It is not clear if these would still work in JUnit5, we would have to test, or migrate them to the equivalent JUnit5 approach - https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4

  2. We make use of Google's JUnit Toolbox which enables us to run lots of JUnit 4 test methods in parallel. JUnit 5 has something itself built in for parallel execution which we could migrate to, but it is marked as "experimental" - https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution

  3. eXist-db's XQueryTestRunner and XMLTestRunner which execute XQSuite tests via JUnit uses JUnit 4's Runner APIs which don't exist in JUnit5. Instead we would need to rewrite these substantially to use JUnit5's TestFactory API - https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests

Now obviously this can all be solved given enough time and resource, but it is going to be quite involved I think. Also, I wonder if now is the right time to move to JUnit 5, as some of the APIs we want to use e.g. parallelism, are marked as experimental.

I am happy for @reinhapa and others to take this forward if they still want to, but personally I probably would not have much time to offer for this as I guess I don't yet see what the benefit of doing so would be?

Copy link
Member

@dizzzz dizzzz left a comment

Choose a reason for hiding this comment

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

see Adams remarks :-(

@reinhapa
Copy link
Member Author

@adamretter the goal of this PR is not the migration of the existing test to the JUnit 5 API . I should enable to use write JUnit 5 tests in addition to the existing ones.

1. We use JUnit rules for starting and stopping the eXist-db server for tests. It is not clear if these would still work in JUnit5, we would have to test, or migrate them to the equivalent JUnit5 approach - https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4

As my existing experience in other project shows,is that there the existing tests can be run using the JUnit Vintage test engine as stated in the migration guide.

2. We make use of Google's JUnit Toolbox which enables us to run lots of JUnit 4 test methods in parallel. JUnit 4 has something itself built in for parallel execution which we could migrate to, but it is marked as "experimental" - https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution

I would suggest to leave the existing tests as they are, until we get the tools running also as JUnit 5 test. I will take a look into this task as soon as we have migrated the test execution to the new JUnit test engines though.

3. eXist-db's `XQueryTestRunner` and `XMLTestRunner` which execute XQSuite tests via JUnit uses JUnit 4's Runner APIs which don't exist in JUnit5. Instead we would need to rewrite these substantially to use JUnit5's TestFactory API - https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests

Here the same approach applies as the existing JUnit tests.

Now obviously this can all be solved given enough time and resource, but it is going to be quite involved I think. Also, I wonder if now is the right time to move to JUnit 5, as some of the APIs we want to use e.g. parallelism, are marked as experimental.

In my opinion this a good time to do so and may give those experimental parts a try and help the JUnit team to improve there code too.

I am happy for @reinhapa and others to take this forward if they still want to, but personally I probably would not have much time to offer for this as I guess I don't yet see what the benefit of doing so would be?

From my part I'm happy if I get some support according the build infrastructure and the way to run the build locally in a way that matches the build environment in order to capture the build failures locally.

@adamretter
Copy link
Member

adamretter commented Mar 28, 2020

@reinhapa Okay... I understand the scope. What I don't understand is how we can have JUnit4 tests which have a dependency on JUnit 4 jar files (especially the JUnit4 runner), run on the JUnit4 engine (even with the vintage dependency).

@reinhapa
Copy link
Member Author

@adamretter the existing JUnit 4 test still need the existing JUnit 4 dependency the execution is done with using the JUnit Vintage test engine dependency, which is a one test engine implementation of the JUnit 5 platform (https://junit.org/junit5/docs/current/user-guide/#overview-what-is-junit-5)

We could implement our own test engine for our XML tests not using any other API than the test engine API itself

@reinhapa
Copy link
Member Author

reinhapa commented Apr 7, 2020

Opened an issue for the current error on junit-team/junit

@joewiz joewiz added enhancement new features, suggestions, etc. and removed in progress Issue is actively being worked upon labels Apr 8, 2020
@joewiz joewiz added this to the eXist-5.3.0 milestone Apr 8, 2020
@joewiz
Copy link
Member

joewiz commented Apr 8, 2020

All 4 linux builds failed on Travis (only the macOS build succeeded) - restarted one linux build to test the waters.

@reinhapa reinhapa force-pushed the junit5 branch 2 times, most recently from 3b0f475 to 03fead0 Compare April 11, 2020 07:12
@reinhapa reinhapa marked this pull request as draft April 11, 2020 07:17
@reinhapa reinhapa force-pushed the junit5 branch 3 times, most recently from 58ac2f9 to cd8f2d8 Compare April 13, 2020 14:15
@reinhapa reinhapa force-pushed the junit5 branch 2 times, most recently from 3db5cb5 to 7bff31b Compare July 13, 2021 14:42
@reinhapa reinhapa marked this pull request as ready for review July 13, 2021 14:43
@reinhapa reinhapa force-pushed the junit5 branch 3 times, most recently from 52c7c42 to 19c3053 Compare July 13, 2021 18:03
}
} else {
try {
embeddedServer.restart();
Copy link
Member

Choose a reason for hiding this comment

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

This seems like every call to getBrokerPool() will restart the database. This seems like it would be very expensive.

Is it that this method is not really named correctly, or that we don't want to restart the database on every getBrokerPool call?

I need to understand this a bit better...

Copy link
Member Author

Choose a reason for hiding this comment

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

I can do a try leaving this away...

Copy link
Member Author

Choose a reason for hiding this comment

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

Seem that when letting this away it leads to non available security manager service though..

Copy link
Member

@dizzzz dizzzz left a comment

Choose a reason for hiding this comment

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

Rebase required, after pulling in Adams last PR (which needs to be rebased)

@reinhapa
Copy link
Member Author

@dizzzz I will rebase as soon as #3985 is merged too..

exist-core/pom.xml Outdated Show resolved Hide resolved
@@ -72,6 +71,6 @@ public Description getDescription() {
};

final RunNotifier notifier = new RunNotifier();
runner.run(notifier);
assertDoesNotThrow(() -> runner.run(notifier));
Copy link
Member

Choose a reason for hiding this comment

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

nice :-)

Copy link
Member

@dizzzz dizzzz left a comment

Choose a reason for hiding this comment

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

Looks great! Only one compile/test/... scope question

Signed-off-by: Patrick Reinhart <patrick@reini.net>
@sonarcloud
Copy link

sonarcloud bot commented Aug 1, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@adamretter adamretter modified the milestones: eXist-6.0.0, eXist-5.3.1 Aug 1, 2021
@adamretter adamretter merged commit a907406 into eXist-db:develop Aug 2, 2021
@reinhapa reinhapa deleted the junit5 branch August 2, 2021 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new features, suggestions, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants