-
-
Notifications
You must be signed in to change notification settings - Fork 352
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
Migrate test suite to JUnit5 #3919
Comments
Hi @slarse, Thanks for opening this issue, this seems a really good task that I can start in this community bonding phase. |
Absolutely! I hope the instructions should be sufficient, but let me know if you need any help. Something that I think I forgot to write in the OP is that you should do one test class per PR, to keep the PRs focused and easy to review :) |
Super useful transformation, thanks for the link |
Hi @slarse, I have one question what is spoon-pom is for, and what is pom is for. I am actually trying to replace
Apart from this, there are other pom files as well, what are they for, and in which pom file(s) should I be adding my dependencies while working on the Spoon core tests? |
We typically put test dependencies into |
With #4570 merged the last JUnit 4 usage in spoon-core is migrated. See https://github.com/search?q=org.junit.Test%3B+repo%3AINRIA%2Fspoon+path%3A%2Fsrc%2F+language%3AJava+language%3AJava&type=Code&ref=advsearch&l=Java&l=Java. |
Nicely done @MartinWitt . Closing. |
Oh the closing was fast.
This question is still open. Otherwise, we can't remove the JUnit 4 dependency easy. |
Point. The question is however not open, the answer is yes migrate them. IMO we can do one subproject per PR. |
So, this issue then closes with the removal of the JUnit4 dependency in Spoon! |
I'd say there is no ownership, it is purely best-effort open-source. If you care, you PR. And yes, agree, it'd be great to port the submodules, one project per PR. Good news, they have light test suites. |
The one situation when that's good news :) |
closing thanks to the gritty work of @MartinWitt! |
We currently have a little bit of JUnit5 (such as VariableTest), but mostly JUnit4 in the test suite. I think it's worth our while to start migrating entirely to JUnit5. Off the top of my head, here are some benefits that come with JUnit5:
The awesomeassertThrows
assertionThis is also very easy to do incrementally, one test class at a time, making it a very good first issue.
Why not keep both?
While we can keep both JUnit4 and JUnit5, and one can even write test cases of both flavors in the same test class, it's just messy to do so due to all of the assertions and annotations having the same simple names. You can also be pretty confident that if a contributor comes into a test class and sees only JUnit4 tests, that contributor will write JUnit4 tests as well. The longer we wait, the more work it will be to leave JUnit4 behind!
How do I know if a test class is using JUnit4?
The easiest way to tell is to look for imports from the JUnit4 API, the most telling one being
import org.junit.Test
. At the moment of writing, there are 189 such imports in the test suite.How do I know if a test class is using JUnit5?
The easiest way to tell is to look for imports from the JUnit5 API, the most telling one being
import org.junit.jupiter.api.Test
. At the moment of writing, there are 3 such imports in the test suite.How can I convert from JUnit4 to JUnit5?
See #3921 for an example.
Some IDEs offer auto-conversion, such as IntelliJ IDEA. But in general, remove any
org.junit
import that is not on the formorg.junit.jupiter
(e.g.import org.junit.Test
should be removed), and then fix any compile or test errors by importing the appropriate classes (e.g.import org.junit.jupiter.api.Test
) and methods from from theorg.junit.jupiter
package. It's really rather straightforward.To check that you've removed all JUnit4 stuff from a test class, you can run the following in a bash-like terminal:
If it prints no output, you're done!
To round off, here are a couple of nice articles about moving from JUnit4 to 5:
Scope of a single PR?
Convert one test class per PR. No more, and no less!
Objections?
If anyone is opposed to this, please raise your voice :). I don't see any harm in migrating test classes, even if we never finish up entirely. 189 also sounds like a big number, but as it's semi-automatic, it typically doesn't take more than a few minutes to migrate a test class (of course, there are exceptions, especially if there's heavy use of
@Rule
).The text was updated successfully, but these errors were encountered: