问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/60961140/how-i-can-install-junit-5-on-vscode