i'm trying to learn unit testing in java and JUnit frame but i'm on how i can and use junit on visual studio code. should i create maven project to that. i tried to import that but it does not work.
Run/Debug test cases# The Test Runner for Java extension will generate shortcuts (the green play button) on the left side of the class and method definition. To run the target test cases, select the green play button. You can also right-click on it to see more options.
First of all, you need to have correctly installed the Java Extention Pack in your VSCode.
Secondly, you need to download a .jar file of your preferred junit5 version. You can visit this link https://search.maven.org/artifact/org.junit.platform/junit-platform-console-standalone/1.7.0-M1/jar and download it as jar file.
After you have downloaded that file you need to add the following lines in your settings.json:
"java.project.referencedLibraries": [
"lib/**/*.jar",
"C:\\PathToFile\\junit-platform-console-standalone-1.6.0.jar"
]
Insert the path to the file you have downloaded.
If you have performed all the above steps correctly, you will be able to run unit tests in VSCode. Also, make sure that your test class and the methods you are testing are both public. It is advised to use the following naming convention for test class (*Test) as some users in GitHub reported problems when it was not used. Regardless that, it is considered good practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With