Questions tagged [junit5]

1

votes
0

answer
7

Views

TempDirectory extension: is there a replacement for createInCustomDirectory() methods?

There used to be createInCustomDirectory() methods in TempDirectory extension class in JUnit 5.4.0-M1 (see docs). The main use case for those methods was to change tmp dir used by the extension. In the final release (5.4.0) TempDirectory extension was made private and enabled by default and those me...
Andrey Pechkurov
1

votes
1

answer
569

Views

Java JUnit 5 AssertAll Stream

I'm having ArrayList( () -> assertTrue(true), ... ) now I'm trying to convert it into an Stream to use assertAll Method. public static void assertAll(Stream executables) throws MultipleFailuresError How can I convert a ArrayList(if there is no cleaner way than ArrayList) into a Stream? Reference: ht...
Hendrik
1

votes
0

answer
16

Views

Android studio: JUNIT test, everytime I select to run single method, it keeps running the entire package test folder

I am trying to run unit test from android studio. I select Run "methodnametest" and it runs the entire package test. What to do? I just want to run methodnametest method. Configuration: Test kind: method repeat: once class: unittestclass method: methodnametest vm options: -ea working directory: pat...
Albertano Santacruz
1

votes
1

answer
26

Views

Mockito showing 0 interactions with mock

Here is my code: public class S3Dao { private final AmazonS3Client amazonS3Client; static final String BUCKET_NAME = "myBucket"; public S3Dao(final AmazonS3Client amazonS3Client) { this.amazonS3Client = amazonS3Client; } public void put(ModelObject modelObject, String playlistId) { this.amazonS3Clie...
Jeremy
0

votes
0

answer
4

Views

How to add Deltaspike classes to WeldJunit5AutoExtension container

Hi my problem at the moment is the following I am using Deltaspikes configuration mechanism with the @Configuration annotation and an interface. See documentation: https://deltaspike.apache.org/documentation/configuration.html I want to unit test my classes by using the weld-junit5 extension for jun...
Kamikazzze
0

votes
2

answer
20

Views

Spring Repository Library Implementation Problem

I using this library but don't know how to implement the DAO Repository class. Please give some idea on how to start. I"m very new to Spring Data Repository. public class UserRepository extends JdbcRepository { public UserRepository(RowMapper rowMapper, String tableName) { super(rowMapper, tableNam...
peterwkc
1

votes
1

answer
78

Views

@IfProfileValue not working with JUnit 5 SpringExtension

I use junit5 with spring-starter-test, in order to run spring test I need to use @ExtendWith instead of @RunWith. However @IfProfileValue work with @RunWith(SpringRunner.class) but not with @ExtendWith(SpringExtension.class), below is my code: @SpringBootTest @ExtendWith({SpringExtension.class}) cla...
Chi Dov
1

votes
2

answer
3.8k

Views

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0

I've got a gradle FAILURE: ..."Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0." Case description: Attached to the project codebase the next libs: APP/biuld.gradle //(Required) Writing and executing Unit Tests on the JUnit Platform testImplementation "org....
1

votes
2

answer
28

Views

How to assert that a proper value was assigned to a private field?

I have the following class: public class Game { @Getter private String gameId; private String player1Id; private String player2Id; private String currentPlayer; private Board board; public Game() { board = new Board(); gameId = UUID.randomUUID().toString(); } public void joinGame(String playerUUID)...
Nikolai
2

votes
0

answer
17

Views

Extension lifecycle and state in JUnit 5

User guide contains following: Usually, an extension is instantiated only once. It's not very clear when extension can be instantiated many times? I'm supporting test suite with multiple extensions and every extension stores it's state in class fields. Everything works fine, but can I rely on this o...
Sergey Guriev
2

votes
1

answer
23

Views

Mockito / Junit5 org.opentest4j.AssertionFailedError for getter()

If I make a JUnit Mockito test in the following method, it fails with org.opentest4j.AssertionFailedError: expected: not null. But the Mockito-(Parameter-)Test before with verify() and Assertions.assertNotNull() is ok. What am I doing wrong or what I don't understand? Here's my code: JUnit5/mock-Tes...
Horst Rothenholzer
1

votes
2

answer
606

Views

How can I test raise exception in JUnit5? [duplicate]

This question already has an answer here: JUnit 5: How to assert an exception is thrown? 8 answers I want to test whether exception works well or not using JUnit5. For example, let say I test queue. public class ArrayCircleQueue { . . . public void enQueue(char item) { if (isFull()) { throw new Ind...
user3595632
17

votes
4

answer
3k

Views

Gradle Jacoco and JUnit5

We just ported our unit tests to JUnit5. Realizing that this is still rather early adoption with little hints on google. The most challenging was to get jacoco code coverage for the Junit5 tests which we use on jenkins. Since this took me almost a day to figure out, I thought I share. Nevertheless,...
C. Ledergerber
2

votes
3

answer
256

Views

Maven does not run @BeforeEach Methods while running

i have a test Class lets call it TestSomething, and a Test Object lets call this one SomeObject. Now i need this Object in every Single Test new this means that i have in my Code a @BeforeEach that loads this Object in a Field: import me.test.SomeObject; import org.junit.jupiter.api.Assertions; imp...
Luca
3

votes
1

answer
22

Views

Java Exception No Tests Found Matching when Junit5 ParameterizedTest Attempt

SO I am trying to use ParameterizedTest from JUnit5 and setup the pom to load everything and now have the following test class. import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matcher...
Patrick Aquilone
19

votes
5

answer
540

Views

Parameterizing with array in Junit 5 (or other testing Java library) in smarter fashion

I'm trying to parameterize this test: @Test public void reverseQuote(double[] qsp) throws Exception { ...} It seems absurd to me that it doesn't exists some quick method to initialize array qsp like, for example, ValueSource: @ParameterizedTest @ValueSource(ints = { 1, 2, 3 }) void testWithValueSour...
Lore
2

votes
1

answer
1.6k

Views

Eclipse keep saying “No tests found with test runner JUnit 5”

I am using Eclipse Oxygen.3 Release (4.7.3). The following is my JUnit test class: import static org.junit.Assert.assertEquals; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; class MyMathTest { MyMath myMath = new My...
Leem
4

votes
2

answer
788

Views

How to pass gradle systemProperties JUnit5 tests?

I am using gradle 3.5 and Unit 5 (jupiter). I wish to pass System property to my tests, in order to configure the test I am running the test using this command gradle test -Denv=envFile1 Here is my gradle file : buildscript { repositories { mavenCentral() } dependencies { classpath 'org.junit.platf...
Shay_t
5

votes
4

answer
1.1k

Views

Parameterised Test Execution in JUnit Jupiter(JUnit5)

Is there a way to have parameterized tests in JUnit Jupiter (Junit5)? @RunWith(Parameterized.class) Background: I went through How to write junit tests for interfaces? and wanted to implement test cases as answered here using JUnit5. But couldn't find the same class/es in the Jupiter package. Attem...
nullpointer
6

votes
2

answer
1.7k

Views

java.lang.NoSuchMethodError when run test with Junit 5

I created a simple test to try Junit 5: import org.junit.jupiter.api.Test; public class MyTest { @Test public void testJupiter() { System.out.println("test"); } } This is the dependency I use: org.junit.jupiter junit-jupiter-api 5.0.0 test Stack trace is the next: Exception in thread "main" java.lan...
IKo
19

votes
2

answer
5.6k

Views

How do I use Hamcrest with JUnit 5 when JUnit 5 doesn't have an assertThat() function?

To use Hamcrest with JUnit 4 we use an assertThat() function. However, JUnit 5 is no longer going to have an assertThat() function. How do I use Hamcrest without an assertThat()?
Max
7

votes
2

answer
2.2k

Views

JUnit 5 does not execute method annotated with BeforeEach

JUnit 5 does not invoke my method in a test class that is annotated with the @BeforeEach annotation, where I initialize some fields of the test object that are needed in the tests. When trying to access these fields inside a test method (method annotated with @Test) I obviously get a NullpointerExce...
David
6

votes
3

answer
11.8k

Views

JUnit 5 - Empty test suite in IntelliJ IDEA when using JUnit Jupiter engine

How to execute All Suite tests with JUnit 5 in IntelliJ IDEA v2016.2.2? I get Empty test suite running this code: import org.junit.platform.runner.IncludeEngines; import org.junit.platform.runner.JUnitPlatform; import org.junit.platform.runner.SelectPackages; import org.junit.runner.RunWith; @RunWit...
Davidea
5

votes
1

answer
5.8k

Views

JUnit 5 and Spring Framework 4.3.x

Is it right, that JUnit 4.12 and junit-vintage-engine (from JUnit 5) can be used together with Spring Framework 4.3.x? Is there a possibility to also use junit-jupiter-api and junit-jupiter-engine (both from JUnit 5)?
Juergen Zimmermann
2

votes
2

answer
349

Views

Do we have any thumb rules to estimate man days for JUnit test cases

We have a project which is 10 years old with more than 10 million lines of java code. Now because of some reasons organization decided to write the JUnit test cases for the old code. We are using Mockito JUnit test cases. As part of this change we have to estimate the man days effort. Its very diffi...
user995656
11

votes
2

answer
3.5k

Views

How do I run JUnit 5 integration tests with the Maven Failsafe plugin?

The Mail Failsafe plugin won't find my JUnit 5 integration tests when I'm running the command mvn clean failsafe:integration-test, although it can find the files. I have the junit-jupiter-api and junit-jupiter-engine as test dependencies: 5.0.1 org.junit.jupiter junit-jupiter-api ${junit.jupiter.ver...
3

votes
1

answer
4.1k

Views

IntelliJ + JUnit 5 (Jupiter)

My build.gradle has: testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0' Using the standard example from http://junit.org/junit5/docs/current/user-guide/ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class FirstJUnit5Tests { @Test void myFirstTes...
clay
3

votes
1

answer
511

Views

JUnit 5, pass information from test class to extension

I am trying to write an extension for Junit5 similar to what I had for Junit4 but I am failing to grasp how to do that in the new (stateless) extension system. The idea in the previous version was that user could pass information into extension class and hence change the way it behaved. Here is a ps...
Siliarus
12

votes
1

answer
2.7k

Views

Executing JUnit 4 and JUnit 5 tests in a same build

In Maven projects, I have some existing tests relying on JUnit 4. I cannot migrate these tests in JUnit 5 for multiple reasons. Essentially, some tests depend on a library which uses JUnit 4 runner and code migration may take time. I would like all the same create new test classes with JUnit 5 that...
davidxxx
4

votes
1

answer
78

Views

How does JUnit mask checked exceptions?

JUnit 5 masks checked exceptions with this code: public static RuntimeException throwAsUncheckedException(Throwable t) { Preconditions.notNull(t, "Throwable must not be null"); ExceptionUtils.throwAs(t); // Appeasing the compiler: the following line will never be executed. return null; } @SuppressWa...
Tim Boemker
3

votes
3

answer
216

Views

What use is @TestInstance annotation in JUnit 5?

Could you give a simple explanation of @TestInstance annotation and how it could be useful in JUnit 5? I think we can achieve the same effect probably by making our fields static.
Mahozad
11

votes
3

answer
7.4k

Views

Gradle project running jUnit 5 tests in IntelliJ

I am trying both Gradle and jUnit5 right now. Everything works fine except that I cannot run a specific jUnit test. The "Run 'SampleTest'" option does not appear when I right-click a test class. I have the latest version of IntelliJ (2016.1.3) Ultimate. Here is my build.gradle file: repositories { m...
12

votes
2

answer
5.7k

Views

Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath in Junit 5

I got following execption when i tried to run test case in junit5: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test (default-test) on project CRUD-App: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test failed: There was an error in...
developerbhuwan
6

votes
3

answer
1.7k

Views

JUnit5: How to repeat failed test?

One of the practice many companies follow is to repeat unstable test until is passes x times (in a row or in total). If it is executed n times and fail to pass at least x times it is marked as failed. TestNG supports that with the following annotation: @Test(invocationCount = 5, successPercentage =...
dzieciou
2

votes
2

answer
450

Views

JUnit test in nested Kotlin class not found when running gradle test

When I specify a test in a nested class in Kotlin as follows ... import org.junit.jupiter.api.* class ParentTest { @Nested class NestedTest { @Test fun NotFoundTest() {} } @Test fun FoundTest() {} } ... it is not recognized by JUnit when running tests using gradle. Only FoundTest is found and ran. I...
Steven Jeuris
2

votes
2

answer
58

Views

JUnit5 testing flattened ArrayList results in false

Why does Junit test show me, that AssertEquals is false for my test? I am flattening this structure and running Junit5 test against it. Arrays.asList("a", Arrays.asList("b", Arrays.asList("c", "d")), "e") Junit test: @Test public void shouldFlattenAListOfList() throws Exception { List flatten = Pro...
nanomader94
2

votes
1

answer
146

Views

Null mock in the constructor test class with MockitoExtension from mockito-junit-jupiter

By using the @MockitoExtension extension from mockito-junit-jupiter, mocks are null in the test class constructor. Used dependencies : mockito-junit-jupiter:2.18.0 unit-jupiter-api:5.1.1 We could reproduce the issue with only a mock field but the use of the mock by the object under test constr...
davidxxx
5

votes
2

answer
855

Views

JDK 9: JUnit 5 test compile with SpringExtension produces java.lang.NoClassDefFoundError: org/w3c/dom/ls/DocumentLS

I believe this problem not to be related to module exclusions in JDK 9 (as with java.se.ee), but rather with the fact that JDK 9 includes a newer version of org.w3c.dom.ls in the java.xml module that does not have the DocumentLS class. The important bit of the stack trace is this: Caused by: org.sp...
2

votes
1

answer
92

Views

JUnit 5 AfterAll not executed on Kotlin

If I run the SubClass unit below I expect @AfterAll to be executed after the test. Yet, the output is just this: init in super class init in sub class test OK I don't understand why SuperClass#stop() is not invoked. I understand that @AfterAll requires a static method or Lifecycle.PER_CLASS but this...
Marcel Stör
5

votes
1

answer
2.2k

Views

Mock autowired dependency in JUnit 5 test for Spring Boot 2 app

Consider the following class under test: public class SomeClass { @Autowired private SomeDependency someDependency; public int inc(int i) { someDependency.doSomething(); return i + 1; } } How can I mock (preferably with Mockito) someDependency in a JUnit 5 (5.0.1) test for a Spring Boot 2 (2.0.0.M2)...
beatngu13

View additional questions