尝试创建JUnit构建配置会导致错误“在模块中找不到JUnit”(IntelliJ)

时间:2018-09-11 04:17:58

标签: java maven intellij-idea junit

我正在Intellij中学习JUnit,但我对IDE有点陌生,而对Java却不熟悉。我能够(貌似)通过Maven安装JUnit而没有麻烦(导入工作和所有东西),但是当我尝试进行构建配置时,我遇到了奇怪的错误。当我尝试在JUnit构建配置模板中指定测试类时,出现此错误:

Can't browse TestCase inheritors: JUnit not found in module

这没有任何意义,因为不仅是我的类路径中所有必需的.jar,而且它们甚至都直接复制到模块中的lib文件夹中,而不是“链接”到。 / p>

All JUnit .jars in the lib folder. Using JUnit 5.2

我已经看到了很多有关如何安装JUnit或使用Maven的问题,但是我已经能够做到这一点。在此IDE中,我还没有看到有关此特定问题的任何信息。

(哦,以防万一,这是我正在使用的代码。这可能与问题无关,这很荒谬,但我想我也应该包括在内)

public class ThingDoer {

    private int foo;
    private int bar;

    public int doThing(int input) {
        bar = input;
        return (foo * foo);
    }

    public int doOtherThing(int input) {
        foo = input;
        return (bar * bar);
    }

}

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class ThingDoerTests {

    @Test
    void testDoThing() {

        ThingDoer d = new ThingDoer();
        int a = d.doThing(10);
        Assertions.assertEquals(0, a);

    }


    @ParameterizedTest
    @ValueSource(ints = {9, 4, 54, 6})
    void testDoOtherThing(int input) {

        ThingDoer d = new ThingDoer();
        Assertions.assertTrue(d.doOtherThing(input) > -100);

    }

}

2 个答案:

答案 0 :(得分:1)

您的项目已正确配置,但是很遗憾,IntelliJ IDEA所显示的消息令人困惑。通过按Class字段中的...按钮创建测试配置的方法仅适用于JUnit 3测试,并且该消息实际上表示“未找到JUnit 3”。 IntelliJ问题跟踪器中有一个关于此问题的open issue

要运行测试,只需右键单击测试类或测试方法,然后从上下文菜单中选择“运行”或“调试”选项。

答案 1 :(得分:0)

在 Android Studio 中,将此行添加到 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="grid-container-PC"> <div class="topBar"> <div class="topBarWrapper"> <div class="container-fluid"> </div> </div> </div> <div class="navBar"> <div class="mainBar"> <div class="searchBar"> </div> <div class="cart"> <div class="cartWrapper"> <div class="iconWrapper1"> <div class="iconContent1"> <a class="tileLink" href=""> <div class="iconPic"> <i class="fas fa-headset"></i> </div> <div class="iconText"> test1 </div> </a> </div> </div> <div class="helpBox1"> <div class="tileListHelpTitle"></div> <ul class="listHelpBox "> <li class="listStyleHelpBox"><a class="linkHelpBox" href="">jhjhj</a></li> </ul> <div class="tileListHelpTitle"></div> <ul class="listHelpBox"> <li class="listStyleHelpBox"><a class="linkHelpBox" href="">jhjj</a></li> <li class="listStyleHelpBox"> <a class="linkHelpBox" href="">jgjhhjhj</a> </li> </ul> <div class="container"> <div class="row"> <div class="col-6"> <div class="dayBoxHelp"> Pon. - pt. </div> </div> <div class="col-6"> <div class="hourBoxHelp"> 9:00 - 16:00 </div> </div> </div> <div class="row"> <div class="col-6"> <div class="dayBoxHelp"> </div> </div> <div class="col-6"> <div class="hourBoxHelp"> dgg </div> </div> </div> </div> </div> <span class="lineHelpBox"></span> <div class="iconWrapper2"> <div class="iconContent2"> <a class="tileLink" href="{% url 'order' %} "> <div class="iconPic"> <i class="fas fa-user"></i> </div> <div class="iconText"> test2 </div> </a> </div> </div> <div class="helpBox2"> <div class="tileListHelpTitle">kjk</div> <div class="loginButtonHelpBox"> <div class="helloMsgLogin"> kjkj</div> <a href="{% url 'login' %}"> <div class="linkLoginHelpBox"> </div> </a> <hr class="hrLogin"> <p class="textHrLogin">kukjk</p> <a href="{% url 'register' %}"> <div class="linkCreateHelpBox"> </div> </a> </div> <ul class="listHelpBox "> <li class="listStyleHelpBox"><a class="linkHelpBox" href="{% url 'order' %}">hjjhj</a></li> </ul> </div> <div class="iconWrapper3"> <div class="iconContent3"> <a class="tileLink" href=""> <div class="iconPic"> <i class="fas fa-shopping-cart"></i> </div> <div class="iconText"> test3 </div> </a> </div> </div> <div class="helpBox3"> <div class="tileListHelpTitle"> text </div> </div> </div> </div> <div class="logoBox"> <div class="logoWrapper"> </div> </div> </div> </div> </div> (app) 中:

build.gradle