本文介绍了使用IntelliJ IDEA设置JUnit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

熟悉Java但不熟悉IntelliJ,如何与JUnit集成入门"?

Familiar with Java but unfamiliar with IntelliJ, how does one "get started" with JUnit integration?

的启发有关如何将JUnit与Intellij IDEA 9.x结合使用的教程,但没有回答我的问题,而是针对较旧版本的IntelliJ的.

Inspired by Looking for a tutorial on using JUnit with Intellij IDEA 9.x which didn't answer my questions and was for an older version of IntelliJ.

推荐答案

基本上,您只需要在类路径上使用junit.jar-这是一种快速的方法:

Basically, you only need junit.jar on the classpath - and here's a quick way to do it:

  1. 确保您已将源文件夹(例如test)标记为 Test Root .

创建一个测试,例如:

public class MyClassTest {
    @Test
    public void testSomething() {

    }
}

  • 由于尚未配置junit.jar(尚未配置),@Test批注将被标记为错误(红色),请按f2导航到它.

  • Since you haven't configured junit.jar (yet), the @Test annotation will be marked as an error (red), hit f2 to navigate to it.

    点击alt并选择将junit.jar添加到类路径

    到此,您就完成了!右键单击您的测试,然后选择 Run'MyClassTest'以运行它并查看测试结果.

    There, you're done! Right-click on your test and choose Run 'MyClassTest' to run it and see the test results.

    Maven注意:或者,如果您使用的是maven,则可以在第4步中选择选项添加Maven依赖项... ,转到搜索工件 >窗格中,键入junit并采用任何版本(例如4.8或4.9).

    Maven Note: Altervatively, if you're using maven, at step 4 you can instead choose the option Add Maven Dependency..., go to the Search for artifact pane, type junit and take whichever version (e.g. 4.8 or 4.9).

    这篇关于使用IntelliJ IDEA设置JUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-01 17:34