简体   繁体   English

无法从 JUnit 导入断言

[英]Cannot import Assertions from JUnit

I am using IntelliJ and JUnit version 5.5.2.我正在使用 IntelliJ 和 JUnit 版本 5.5.2。 I've imported the Test annotations without any problems but I cannot get assertEquals methods to be recognised.我已经毫无问题地导入了 Test 注释,但我无法识别 assertEquals 方法。

I've tried the following imports:我尝试了以下导入:

import static org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*; 

The closest I got is wih the last line, but then I get an error "Cannot resolve method assertEquals".我得到的最接近的是最后一行,但随后出现错误“无法解析方法 assertEquals”。 I am trying to test my method from another class that converts a binary number to decimal.我正在尝试从另一个将二进制数转换为十进制数的 class 测试我的方法。

Here is the full code:这是完整的代码:

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;


public class Einstiegsbeispieltest {

Einstiegsbeispiel testObject = new Einstiegsbeispiel();

@Test
public void testOne() {
assertEquals(14, testObject.binary2decimal(1110));
}
}

I've googled everywhere but no avail.我到处搜索,但无济于事。

This method might be returning void instead of int.此方法可能返回 void 而不是 int。 testObject.binary2decimal(1110)); testObject.binary2decimal(1110));
please change method to return it to int.请更改方法以将其返回为 int。

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

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