Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can install junit 5 on VSCode

Tags:

java

junit

junit5

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.

like image 714
Yacine_Dev_Artist Avatar asked Mar 31 '20 22:03

Yacine_Dev_Artist


People also ask

How do I run a JUnit test case in VS Code?

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.


1 Answers

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.

like image 153
Alex R. Avatar answered Oct 31 '22 23:10

Alex R.