vargashj
vargashj

Reputation: 39

JUnit 5 a very simple test keeps resolving on Undefined

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

Upvotes: 0

Views: 555

Answers (2)

Basil Bourque
Basil Bourque

Reputation: 339502

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" ) );
    }
}

Upvotes: 3

Halil Sahin
Halil Sahin

Reputation: 603

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

assertEqual(String1, String2);

Upvotes: 1

Related Questions