我如何在VSCode上安装Junit 5 [英] How i can install junit 5 on VSCode

查看:1169
本文介绍了我如何在VSCode上安装Junit 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习Java和JUnit框架中的单元测试,但是我正在研究如何在Visual Studio代码上使用junit. 我应该为此创建Maven项目. 我尝试导入该文件,但是它不起作用.

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.

推荐答案

首先,您需要在VSCode中正确安装Java扩展包.

First of all, you need to have correctly installed the Java Extention Pack in your VSCode.

第二,您需要下载首选junit5版本的.jar文件. 您可以访问此链接 https://search.maven.org/artifact/org.junit.platform/junit-platform-console-standalone/1.7.0-M1/jar 并下载为jar文件.

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.

下载该文件后,需要在settings.json中添加以下行:

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"
]

插入已下载文件的路径.

如果正确执行了上述所有步骤,则可以在VSCode中运行单元测试.另外,请确保您的测试类和要测试的方法都是公开的.建议对测试类(* Test)使用以下命名约定,因为GitHub中的某些用户在不使用它时会报告问题.不管怎样,这被认为是很好的做法.

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.

这篇关于我如何在VSCode上安装Junit 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆