Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to run any Junit4 tests – InvalidTestClassError: Invalid test class

I am trying to run Junit4 tests and I am unable to run it. I have the following dependency installed

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version>
    <scope>test</scope>
</dependency>

My test class looks like this

package model.validators;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

class UserValidatorTest {

    @Test
    public void shouldReturnTrueForValidPhoneNumbers() {
        List<String> phoneNumbers = Arrays.asList(
                "9876543210",
                "7777543210"
        );
        boolean result = UserValidator.validateUserPhoneNumbers(phoneNumbers);

        Assert.assertTrue(result);
    }
}

When I try to run this test, I get the following error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

org.junit.runners.model.InvalidTestClassError: Invalid test class 'model.validators.UserValidatorTest':

I am using IntellijIdea. Any idea what is going wrong here ? TIA

Tried changing dependencies, reloading maven project, setting the correct classpath in Junit Run configurations

>Solution :

I can see that your class UserValidatorTest is not public. On making your class public, you will be able to run the tests.

package model.validators;

import org.junit.Assert;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

public class UserValidatorTest {

    @Test
    public void shouldReturnTrueForValidPhoneNumbers() {
        List<String> phoneNumbers = Arrays.asList(
                "9876543210",
                "7777543210"
        );
        boolean result = UserValidator.validateUserPhoneNumbers(phoneNumbers);

        Assert.assertTrue(result);
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading