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

JUnit 5 Support #55

Open
AustinShalit opened this issue Oct 2, 2017 · 25 comments
Open

JUnit 5 Support #55

AustinShalit opened this issue Oct 2, 2017 · 25 comments

Comments

@AustinShalit
Copy link

@AustinShalit AustinShalit commented Oct 2, 2017

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

@stefanbirkner
Copy link
Owner

@stefanbirkner stefanbirkner commented Oct 7, 2017

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

@kn9wBP2JX
Copy link

@kn9wBP2JX kn9wBP2JX commented Oct 12, 2017

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

@stefanbirkner
Copy link
Owner

@stefanbirkner stefanbirkner commented Oct 14, 2017

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

@sbrannen
Copy link

@sbrannen sbrannen commented Oct 14, 2017

I start development tomorrow.

Awesome. Looking forward to it! 👍

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

@sbrannen
Copy link

@sbrannen sbrannen commented Oct 14, 2017

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. 😉

@deepakab03
Copy link

@deepakab03 deepakab03 commented Apr 2, 2018

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?

@stefanbirkner
Copy link
Owner

@stefanbirkner stefanbirkner commented Apr 4, 2018

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
Copy link
Owner

@stefanbirkner stefanbirkner commented Apr 25, 2018

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

@stefanbirkner
Copy link
Owner

@stefanbirkner stefanbirkner commented Apr 26, 2018

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.

@syhily
Copy link

@syhily syhily commented May 28, 2018

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

@davidkarlsen
Copy link

@davidkarlsen davidkarlsen commented Aug 8, 2018

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.

@stefanbirkner
Copy link
Owner

@stefanbirkner stefanbirkner commented Aug 8, 2018

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

@davidkarlsen
Copy link

@davidkarlsen davidkarlsen commented Aug 8, 2018

Well - not really the lambda case. I've migrated from junit4 to junit5, see stefanbirkner/fake-sftp-server-rule#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?

@usulkies
Copy link

@usulkies usulkies commented Jan 21, 2019

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

@stefanbirkner
Copy link
Owner

@stefanbirkner stefanbirkner commented Jan 22, 2019

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

@RonCrocker
Copy link

@RonCrocker RonCrocker commented Mar 14, 2019

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

@stefanbirkner
Copy link
Owner

@stefanbirkner stefanbirkner commented Mar 14, 2019

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.

@cmathiesen
Copy link

@cmathiesen cmathiesen commented Jul 24, 2019

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 :)

@maguro
Copy link

@maguro maguro commented Aug 23, 2019

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?

bdpiprava referenced this issue in gocd/gocd Sep 19, 2019
@deeTEEcee
Copy link

@deeTEEcee deeTEEcee commented Oct 29, 2019

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 :)

@michaelruocco
Copy link

@michaelruocco michaelruocco commented Nov 25, 2019

@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!

@Purus
Copy link

@Purus Purus commented Jan 24, 2020

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
Copy link

@michaelruocco michaelruocco commented Apr 21, 2020

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!

@ashleyfrieze
Copy link

@ashleyfrieze ashleyfrieze commented Nov 18, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet