Home > Enterprise >  JUnit 5 a very simple test keeps resolving on Undefined
JUnit 5 a very simple test keeps resolving on Undefined

Time:07-12

How is this possible? - Thanks for your help

I am on Intellij Community 2022 and I cant believe this Assert is failing.

Assert.assertTrue(new String("ss").equals("ss")) // this fails
Assert.assertTrue(new String("ss").matches("ss")) // this fails

enter image description here

CodePudding user response:

For compare to String expressions you have to use assertEqual function. Usage:

assertEqual(String1, String2);

CodePudding user response:

Assertions, not Assert

No Assert class in JUnit Jupiter.

Use Assertions class.

org.junit.jupiter.api.Assertions.assertTrue( new String( "ss" ).equals( "ss" ) );

Tests passed: 1 of 1

For less typing, use static import.

package work.basil.example.squarematrix;

import org.junit.jupiter.api.Test;

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

class SquareMatrixTest
{
    @Test
    void report ( )
    {
        assertTrue( new String( "ss" ).equals( "ss" ) );
    }
}
  • Related