2

I am using Junit5, and my IDE (IntelijIdea) is not recognize Assumptions. I am actually do not know why, but may be there is some dependecy on Maven I do not connect into project. Below I will show you the sample of my code.

This is my Assumptions import.

import org.junit.jupiter.api.Assumptions;

And this is wrong code (I can not compile it, compiler does not know what is assumeTrue() )

@Test
@EnabledOnOs(OS.MAC)
void testInsertion() {
    assumeTrue(isServerUp); //That place is crashing
    assertThrows(NullPointerException.class, () -> Connection.insertTheInstance(person),
            "");

If you are familiar with this case then, please, share you knowledge) Many thanks!

Mikhail
  • 195
  • 2
  • 12
  • JUnit 5 consists of several modules and assumptions are a part of `junit-jupiter-api` library, so you need this dependency in your pom file, e.g. the latest stable version is [5.6.2](https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api/5.6.2) – Yevhen Danchenko Jun 02 '20 at 05:03
  • Can you compile project from command line by Maven? – Andrey Jun 02 '20 at 08:19
  • No, I have tried) – Mikhail Jun 02 '20 at 09:05

2 Answers2

1

It's a import problem probably. Try:

  <dependency>
     <groupId>org.junit.jupiter</groupId>
     <artifactId>junit-jupiter-api</artifactId>
     <version>5.6.2</version>
     <scope>test</scope>
  </dependency> 
  • Check if maven import is ok
  • Close your project in intellij
  • Delete your .m2 folder in your HOME directory (user/yourusername in windows, /home in linux)
  • Execute in a terminal in your project: mvn dependency:purge-local-repository clean.
  • Open your project again

If it's not ok yet, try the junit 4.12. Its have Assumptions too.

0

assumeTrue method is part of JUnit 4, but you can also use it in JUnit 5 through the

org.junit.jupiter.api.Assumptions class.

For intelliJ - Junit5 combination, make sure to import the following in your class:

import static org.junit.jupiter.api.Assumptions.assumeTrue;