Open AustinShalit opened 7 years ago
Yes, I create a JUnit Jupiter extension at the end of October. I post updates here.
@stefanbirkner What can you suggest to use with JUnit 5 for stdout capturing?
Pleased wait for my JUnit Jupiter extension. I start development tomorrow.
I start development tomorrow.
Awesome. Looking forward to it! 👍
... b/c I otherwise might have to put something together myself. 😉
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. 😉
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?
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 :-(
The rewrite of the tests is finished. After fixing #61 I create a library that is independent of JUnit 4.
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.
https://gist.github.com/syhily/1ae31ba0394668eb040917387a698449 Implemented a JUnit5 based ExpectedSystemExit
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.
I think you are talking about Fake SFTP Server Lambda. Can you create an issue here and describe what you are looking for.
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?
Is there a way already to use System Rules (to set environment variable) in Junit 5?
Unfortunately not, but I found some time to continue my work on System Lambda.
+1 for finishing up migrations to JUnit5, particularly for EnvironmentVariables
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
.
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 :)
The replacement for EnvironmentVariables is the method
withEnvironmentVariable
together with the inner classEnvironmentVariables
.
I'm sure I'm being dense. How can I set the environmental variables once, for all tests to share?
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 :)
@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!
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..
@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/
Sharing for others, incl. @maguro @purus @deeTEEcee
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!
Jupiter support available in https://github.com/webcompere/system-stubs/tree/master/system-stubs-jupiter - a fork of system-lambda
Just seeing if there are any plans to support JUnit 5 right now.