Intellij无法解析符号RunWith,即使找到了maven依赖项

问题描述 投票:2回答:3

我的IntelliJ IDEA看到了JUnit 4 Maven依赖项。

Dependecies of JUNIT in the project

但不能解析来自这些依赖项的任何符号

enter image description here

任何想法?

java maven intellij-idea junit
3个回答
1
投票

我遵循了这些步骤,并且能够使用Intellij代码洞察力对TestCase进行编码。

在shell中,我执行了以下操作

mkdir so33987661
mkdir so33987661/src/
mkdir so33987661/src/test
mkdir so33987661/src/test/java
cd so33987661
vi pom.xml

我的pom.xml

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.so33987661</groupId>
    <artifactId>my-project</artifactId>
    <version>1.0</version>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

返回Intellij,选择文件菜单,新建现有来源的项目

打开so33987661/pom.xml文件。

检查自动导入Maven项目enter image description here

通过单击下一步直到创建项目,接受其余屏幕的默认设置。

导航到src/test/java文件夹并创建新的测试和代码,代码,代码。

import org.junit.Test;
import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
public class BookSearchTest {

    @Test
    public void testIt() throws Exception {
        // todo: testIt()!
    }
}

enter image description here


0
投票

我遇到了同样的问题。打开您的pom.xml,找到“ junit”。查看范围值,也许是“测试”。如果您在主程序包中导入junit,则intellij的想法将引发错误,但不会使日蚀。在适当的范围内使用junit可以解决问题。我已修正错误。


0
投票

#1检入设置->构建,执行,部署->构建工具-> maven,是否正确设置了“用户设置文件”和(如果使用本地存储库)“本地存储库”路径。 >

#2

检查设置->构建,执行,部署->编译器-> Java编译器是否期望目标字节码版本。 (有时在添加新的依赖项后,Intelli会将其设置为1.5)

#3

在项目设置中(默认快捷键ctrl + alt + shift + s)项目设置->项目
  • ProjectSDK应该指向正确的目的地

  • 项目语言级别应为您使用的版本

  • 项目设置->模块中

语言级别应为您使用的版本
© www.soinside.com 2019 - 2024. All rights reserved.