embedded-ldap-junit icon indicating copy to clipboard operation
embedded-ldap-junit copied to clipboard

Add support for JUnit 5 extensions (#57)

Open bjansen opened this issue 4 years ago • 13 comments

Update here: https://github.com/zapodot/embedded-ldap-junit/pull/67#issuecomment-889780610

~~Notes:~~ ~~* I didn't copy/adapt the full test suite because the code I put in the abstract classes is already tested by the Rule tests. I only added tests that make sure the builder works and the Extension starts/stops the server correctly.~~ ~~* I declared the junit-jupiter-api Maven dependency as optional to not force JUnit 5 down the throat of existing projects that use JUnit 4.~~ ~~* I considered changing the junit dependency to be optional too, but didn't do it because that could possibly break projects that don't pull JUnit 4 explicitly when they upgrade embedded-ldap-junit to the next version.~~

bjansen avatar Oct 28 '20 19:10 bjansen

Coverage Status

Coverage decreased (-76.7%) to 14.8% when pulling 6550282a3b28eb327fa502daa2b9682c71235f55 on bjansen:issue-57-junit5 into d43da049898e5619c9ad1ea24c98d0a00124ef7e on zapodot:master.

coveralls avatar Oct 28 '20 21:10 coveralls

I realized it might be a better design to split the code into separate modules, like what was done in https://github.com/zapodot/embedded-jms-junit for example. Better separation of concerns, no dual dependency on JUnit 4 and JUnit 5 etc. But that will introduce quite a lot of changes in the project structure. WDYT @zapodot?

bjansen avatar Oct 29 '20 08:10 bjansen

Thanks for your contribution! You are right: It would be better to split JUnit 4 and JUnit 5 support into two separate modules.

zapodot avatar Oct 29 '20 09:10 zapodot

All right, I think I can get it to work without breaking compatibility with older versions (especially the Maven coordinates).

bjansen avatar Oct 29 '20 09:10 bjansen

One remaining problem after modularization: most of the unit tests are in embedded-ldap-junit, but most of the code is in embedded-ldap-core, so cobertura reports very low coverage even when most of the code is well tested.

bjansen avatar Oct 29 '20 11:10 bjansen

Good news! I moved (actually copied) most of the unit tests from embedded-ldap-junit to embedded-ldap-core, and the coverage is now on par with what's currently on master.

I suppose I could remove most of the tests in embedded-ldap-junit which are now redundant, and only leave what's testing the actual JUnit rule stuff, and not the embedded LDAP server. WDYT @zapodot?

So, to summarize:

  • The project is now split into 3 modules:
    • embedded-ldap-core contains most of the code to setup an embedded LDAP server, and is not tied to any testing framework. It has good code coverage.
    • embedded-ldap-junit is a JUnit 4 rule that starts this embedded LDAP server
    • embedded-ldap-junit5 is a JUnit 5 extension that starts this embedded LDAP server
  • This new version should not break anything in existing projects, because Maven coordinates remain the same (the only difference is that embedded-ldap-junit now has an extra dependency on embedded-ldap-core). Package names and class names remain the same.
  • Now that the project is modularized, it's possible in theory to add support for new testing frameworks that have an equivalent of JUnit's @Rule.

bjansen avatar Jul 30 '21 09:07 bjansen

I think there's an extra change that I could do: embedded-ldap-core is now mostly abstract classes, but I could add a Simple/Default implementation that would turn the thing into a standalone module.

People who want to embed a simple LDAP server in their application (outside of the context of unit tests) could simply pull embedded-ldap-core and use its builder to set up their server!

bjansen avatar Jul 30 '21 09:07 bjansen

Any updates on this PR? 🤔

dzikoysk avatar Dec 09 '21 19:12 dzikoysk

@bjansen any chance that you can rebase from the master branch?

zapodot avatar Aug 11 '22 12:08 zapodot

bump....

jrivard avatar Dec 18 '22 23:12 jrivard

I rebased from master, I'll probably squash the commits before merging.

bjansen avatar Dec 26 '22 10:12 bjansen

@bjansen @zapodot Any idea when this could be merged? It's kind of usefull :wink:

Erates avatar Mar 26 '24 06:03 Erates

@zapodot do you think you could find some time to review this PR?

bjansen avatar Jun 07 '24 16:06 bjansen