找不到 NetBeans 10 JUnit Jar [英] NetBeans 10 JUnit Jar not found

查看:71
本文介绍了找不到 NetBeans 10 JUnit Jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我新安装了 NetBeans 10.尝试运行我刚创建的一些初始单元测试时,出现以下错误:

I have a new installation of NetBeans 10. Trying to run some initial unit tests I just created, I get the following error:

对于 必须包含 junit.jar 如果不在 Ant 自己的类路径中

The <classpath> or <modulepath> for <junit> must include junit.jar if not in Ant's own classpath

我可能会修改构建脚本以包含 junit.jar,但我想知道:解决这个问题的正确方法是什么?

I could probably hack the build script to include junit.jar, but I want to know: what's the right way to fix this?

NetBeans 不应该附带一个已经可以访问的 JUnit 版本吗?我应该以不同的方式配置我的项目吗?如何添加库的路径?

Shouldn't NetBeans come with a version of JUnit already accessible? Should I configure my project differently? How do I add a path to the library?

如何找到 Ant 的类路径(以及 NetBeans 使用的版本/二进制文件)?

How can I find the classpath for Ant (and what version/binary NetBeans is using)?

项目 Test Libraries 显示存在 JUnit 5.3.1,我在那里列出了三个 Jar 文件:junit-jipiter-api、junit-jupiter-params、junit-jupiter-engine.但是好像实际上没有找到.

The project Test Libraries shows that JUnit 5.3.1 is present, I have three Jar files listed there: junit-jipiter-api, junit-jupiter-params, junit-jupiter-engine. But it seems to be not actually found.

该项目是一个标准的 Java 库(没有主类).我没有添加任何额外"或弄乱 NetBeans 使用的默认项目设置.刚刚使用了基本的设置向导.

The project is a standard Java Library (no main class). I didn't add any "extras" or mess with the default project setup that NetBeans uses. Just used the basic setup wizard thing.

再.Geertjan Wielenga 来自 NetBeans 邮件列表的回复,他指着我在这个帖子上回复:

Re. a reply from the NetBeans mailing list by Geertjan Wielenga, he pointed me at this thread and reply:

是的...

我们从未在 NB 10 中为基于 Ant 的项目实现 JUnit 5 支持.

We never got around to implementing JUnit 5 support for Ant based projects in NB 10.

约翰麦克唐纳

noreferrel://mail-archives.apache.org/mod_mbox/netbeans-users/201901.mbox/%3cCAAuDyk6WcgLaUDz0dp=4Arr7QGnwWcYey3VOeGojRRMRqVZrFA@mail.gmail.com%3e

所以我认为这行不通.我将尝试在下面建议恢复到 JUnit 4.

So I think it's just not going to work. I'll try the suggested reversion to JUnit 4 below.

推荐答案

如果有帮助的话,我也在 xubuntu 中运行 netbeans 10.我不知道发生了什么,所以我不得不恢复到 junit4.完全清楚,ant 需要 junit.jar,它在默认的 netbeans 10 安装中找不到.在有人提出更好的解决方案之前,请返回 junit4:

I'm running netbeans 10 as well, in xubuntu if that helps. I have no idea what is going on, so I had to revert to junit4. To be perfectly clear, ant needs junit.jar which is nowhere to be found in the default netbeans 10 installation. Until someone brings a better solution, revert to junit4:

1) 在您的测试库中,右键单击并导入 junit 4.1.2 库.

1) in your test libraries, right click and import the junit 4.1.2 ones.

2) 删除 junit 5.3 的那些.

2) remove the junit 5.3 ones.

3) 废弃测试文件中的所有导入并使用 junit4 导入.即你的进口看起来像:

3) scrap all the imports in your test file and use the junit4 ones. ie your imports will look like:

import static junit.framework.Assert.assertEquals;
import org.junit.Test;
import org.junit.*;
/*import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;*/

4) 废弃 beforeAll 和其他测试标签.只留下@Test 一个.

4) scrap the beforeAll and other test tags. Only leave the @Test one.

5) 全部保存,关闭并重新打开项目.它会抱怨没有导入 junit4 的 hamcrest 库.让 netbeans 为您修复它.

5) save all, close and re-open the project. It will complain that the hamcrest libraries for junit4 are not imported. Allow netbeans to fix it for you.

完成后,我能够测试成功和失败的测试.我猜当你用模板生成器生成 junit 测试时,它会生成 junit5 的,所以,有点烦人.但是你会有测试!

With that done, I was able to test successful and failing tests. I guess when you generate the junit tests with the template generator, it will generate the junit5 ones, so, a bit annoying. But you'll have tests!

这篇关于找不到 NetBeans 10 JUnit Jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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