system-rules icon indicating copy to clipboard operation
system-rules copied to clipboard

JUnit 5 Support

Open AustinShalit opened this issue 8 years ago • 25 comments
trafficstars

Just seeing if there are any plans to support JUnit 5 right now.

AustinShalit avatar Oct 02 '17 01:10 AustinShalit

Yes, I create a JUnit Jupiter extension at the end of October. I post updates here.

stefanbirkner avatar Oct 07 '17 13:10 stefanbirkner

@stefanbirkner What can you suggest to use with JUnit 5 for stdout capturing?

kn9wBP2JX avatar Oct 12 '17 15:10 kn9wBP2JX

Pleased wait for my JUnit Jupiter extension. I start development tomorrow.

stefanbirkner avatar Oct 14 '17 12:10 stefanbirkner

I start development tomorrow.

Awesome. Looking forward to it! 👍

... b/c I otherwise might have to put something together myself. 😉

sbrannen avatar Oct 14 '17 14:10 sbrannen

BTW, I've been meaning to show the Spring Boot team how to migrate their OutputCapture rule for JUnit 4 to JUnit Jupiter for a long time, so I just did it...

https://twitter.com/sam_brannen/status/919230917129981953

Not that you, @stefanbirkner, plan to do it the same way, but perhaps it serves as inspiration for you. 😉

sbrannen avatar Oct 14 '17 16:10 sbrannen

Hello Stefan, I find the system-rules lib very useful and easy to use, thanks to you all! Any idea when you intend to release support for JUnit 5, so that we can do away with JUnit 4 as a dependency?

deepakab03 avatar Apr 02 '18 14:04 deepakab03

Currently I'm working on two things:

I cannot estimate a release date because it depends very much on the amount of free time that I'm able to spend on System Rules. I started mid October last year and I'm still not finished :-(

stefanbirkner avatar Apr 04 '18 20:04 stefanbirkner

The rewrite of the tests is finished. After fixing #61 I create a library that is independent of JUnit 4.

stefanbirkner avatar Apr 25 '18 06:04 stefanbirkner

I started to create a library called System Lambda that solves the same testing problems like System Rules but without a dependency to a test framework. There may be a JUnit Lambda extension afterwards, but I start with an independent library because it can be used by TestNG users, too.

stefanbirkner avatar Apr 26 '18 07:04 stefanbirkner

https://gist.github.com/syhily/1ae31ba0394668eb040917387a698449 Implemented a JUnit5 based ExpectedSystemExit

syhily avatar May 28 '18 02:05 syhily

The lambda stuff for sftp is really nice, but sometimes the port is needed before at the class initialization level, so that it can be injected into systemproperties for spring-boot to pick it up before initialization. This is not possible when I cannot control the lifecycle myself.

davidkarlsen avatar Aug 08 '18 08:08 davidkarlsen

I think you are talking about Fake SFTP Server Lambda. Can you create an issue here and describe what you are looking for.

stefanbirkner avatar Aug 08 '18 12:08 stefanbirkner

Well - not really the lambda case. I've migrated from junit4 to junit5, see https://github.com/stefanbirkner/fake-sftp-server-rule/issues/11 for the initial issue. Since junit4 rules are not junit5 compatible (except in the cases where the migration trick from junit is used - and that requires the junit-rules to be based on certain base-classes) I looked at using the lamba-based library instead - but that comes with it sets of problems, since I need the port - so that I can set this in a system property - so that the port is read by the spring-configuration - and that needs to happen before spring-test initializes.

WDYT?

davidkarlsen avatar Aug 08 '18 21:08 davidkarlsen

Is there a way already to use System Rules (to set environment variable) in Junit 5?

usulkies avatar Jan 21 '19 09:01 usulkies

Unfortunately not, but I found some time to continue my work on System Lambda.

stefanbirkner avatar Jan 22 '19 21:01 stefanbirkner

+1 for finishing up migrations to JUnit5, particularly for EnvironmentVariables

RonCrocker avatar Mar 14 '19 17:03 RonCrocker

In the meantime you can copy code from https://github.com/stefanbirkner/system-lambda/blob/master/src/main/java/com/github/stefanbirkner/systemlambda/SystemLambda.java The replacement for EnvironmentVariables is the method withEnvironmentVariable together with the inner class EnvironmentVariables.

stefanbirkner avatar Mar 14 '19 20:03 stefanbirkner

Hello! Just wanted to chime in and mention that I've been working on updating our tests to JUnit5 and I tried using your EnvironmentVariables class from SystemLambda and it works very nicely! We're looking forward to a future release :)

cmathiesen avatar Jul 24 '19 10:07 cmathiesen

The replacement for EnvironmentVariables is the method withEnvironmentVariable together with the inner class EnvironmentVariables.

I'm sure I'm being dense. How can I set the environmental variables once, for all tests to share?

maguro avatar Aug 23 '19 14:08 maguro

i don't think you're being dense. it's pretty unclear to me what to do because there's a link to something that has a method and inner class WithEnvironmentVariable and there's a file called EnvironmentVariables.java elsewhere. Basically, I don't know what to do here either :)

deeTEEcee avatar Oct 29 '19 00:10 deeTEEcee

@stefanbirkner thanks for the very useful library! I am keen for JUnit 5 support too, I like the look of the system-lambda library and would be happy to switch over when it is released, do you require any help in trying to get it ready for release? I would probably take a while to learn enough to provide anything useful but would happily try to help.

@deeTEEcee + @maguro just incase it helps I managed to make use of the system lambda code to set environment variables for my Junit 5 tests, these classes should help, but feel free to ask if anything is not clear?

I copied (and slightly adjusted) these two classes: https://github.com/michaelruocco/idv/tree/988cdfe45358764e8dc7e11d5efaa2daed5c769c/app/spring-app/src/test/java/uk/co/idv/app/environment. Then my tests that set the environment variables are here: https://github.com/michaelruocco/idv/blob/3f086a6ce2ab7afad5cf2d80d3f85be6e4fd6102/app/spring-app/src/test/java/uk/co/idv/app/config/MongoConnectionStringTest.java. I won't profess to understand all the code inside the WithEnvironmentVariables class does, but I understood enough to get it working!

michaelruocco avatar Nov 25 '19 20:11 michaelruocco

Hello! Just wanted to chime in and mention that I've been working on updating our tests to JUnit5 and I tried using your EnvironmentVariables class from SystemLambda and it works very nicely! We're looking forward to a future release :)

Could you please share how you used it..

Purus avatar Jan 24 '20 10:01 Purus

@michaelruocco Your links were 404'ing, found out you switched to junit-pioneer's system-properties for Junit5 support. Thanks

https://github.com/junit-pioneer/junit-pioneer https://junit-pioneer.org/docs/system-properties/

via https://github.com/michaelruocco/idv/blob/master/utils/aws-system-properties/src/test/java/uk/co/idv/utils/aws/system/AwsSystemPropertiesTest.java

Sharing for others, incl. @maguro @purus @deeTEEcee

amit-dd avatar Apr 21 '20 19:04 amit-dd

Hi @amit-dd, yeah you are quite right, the reason the links are 404ing is because I decided going with system properties was a simpler solution in the end. In case you are interested, the old links with the code I used for environment properties are below:

This was the class copied and tweaked from this library: https://github.com/michaelruocco/idv/blob/988cdfe45358764e8dc7e11d5efaa2daed5c769c/app/spring-app/src/test/java/uk/co/idv/app/environment/WithEnvironmentVariables.java

An example of this being used is here: https://github.com/michaelruocco/idv/blob/ebbc91a05c4ef824b7cb458d9aa53cb1a57bb4ec/app/spring-app/src/test/java/uk/co/idv/app/ApplicationTest.java#L37

Hope that helps! Additionally I have updated the links on the old comment to the point to the commit references where they used to live. Thanks for pointing out the dead links!

michaelruocco avatar Apr 21 '20 20:04 michaelruocco

Jupiter support available in https://github.com/webcompere/system-stubs/tree/master/system-stubs-jupiter - a fork of system-lambda

ashleyfrieze avatar Nov 18 '20 11:11 ashleyfrieze