简体   繁体   English

如何在 Eclipse 中的 JUnit 视图为空时运行断言测试

[英]How to run assertion test when JUnit view is empty in Eclipse

I've been following along a couple of tutorials and at the point where they run the tests in the junit test view in Eclipse, mine just looks disabled, and I can see any tests to run:我一直在关注几个教程,并在他们在 Eclipse 的 junit 测试视图中运行测试时,我的只是看起来被禁用,我可以看到任何要运行的测试:

Eclipse 和 JUnit 视图的屏幕截图

Notice on the right hand side I have an empty JUnit view.请注意,在右侧我有一个空的 JUnit 视图。 None of the tutorials mention anything about this situation.没有任何教程提到这种情况。 You can see the JUnit library in my Package Explorer too.您也可以在我的 Package Explorer 中看到 JUnit 库。 What do I need to do now to get my test to run in the JUnit test view?我现在需要做什么才能让我的测试在 JUnit 测试视图中运行?

You got the project setup right, now you need to tell eclipse to execute the test cases locate in the project, for that you need to do the following 您已经正确设置了项目,现在需要告诉Eclipse执行项目中的测试用例,为此,您需要执行以下操作

Right click project --> run as --> Junit Test 右键单击项目->运行方式-> Junit测试

在此处输入图片说明

And the Junit view of the eclipse will get populated with the test runs as below with the results of which cases failed and which passed Eclipse的Junit视图将通过以下测试运行填充,其中哪些案例失败以及哪些案例通过的结果

在此处输入图片说明

Just right click on AssertTest.java ; 只需右键单击AssertTest.java then follow below-- 然后按照以下说明-

run as > Junit Test 运行为> Junit Test

Since looking into your screen shot, you only have one Junit class; 自从查看屏幕快照以来,您只有一个Junit类; so it seems this will help you to run Junit. 因此,这似乎将帮助您运行Junit。

I found this post while looking into a slightly different "empty JUnit view" issue: after upgrading to Eclipse 2022.06 from 2021.??, my JUnit view stopped working.我在查看略有不同的“空 JUnit 视图”问题时发现了这篇文章:从 2021 年升级到 Eclipse 2022.06 后,我的 Z8965A291ED0E584870298E 视图停止工作I could see the unit tests running in the console, but no results were shown in the view.我可以看到在控制台中运行的单元测试,但视图中没有显示任何结果。

I was able to fix it by opening the Eclipse preferences Java -> JUnit, then clicking Apply and Close.我可以通过打开 Eclipse 首选项 Java -> JUnit 来修复它,然后单击应用并关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM