assertj 断言 assertThat 未解决

assertj Assertions assertThat is not resolved

奇怪的行为。我有一个用 initializr 制作的香草 spring 引导项目。 build.gradle 在下方,如您所见,它加载了 spring 启动启动器测试的测试依赖项,其中包括 assertj 包。

plugins {
    id 'org.springframework.boot' version '2.5.4'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.acme'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-webflux'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'io.projectreactor:reactor-test'
}

test {
    useJUnitPlatform()
}

但是,我在这里有我的第一个测试组件

package com.foretold.astrocalc.app.controllers;

import org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class ChartControllerTest {

    @Autowired
    private ChartController controller;

    @Test
    public void contextLoads() throws Exception{
        assertThat(controller).isNotNull();
    }

}

IJ 告诉我它无法解析符号 assertThat。它在 import 语句中最多加载 Assertions,并且在其中。当我单击进入 Assertions class 时,我看到了 public 方法 assertThat。是否有一些 IJ 设置搞砸了静态导入?

仅导入 Assertions 并使用带点符号的方法确实有效,但为什么静态导入不起作用?

当我们想在 AssertJ 中编写断言时,我们必须改用静态 assertThat 方法。 这意味着您必须像下面这样导入它:

import static org.assertj.core.api.Assertions.assertThat;