junit5

IntelliJ + JUnit 5 (Jupiter)

你。 提交于 2019-12-22 10:59:47
问题 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 myFirstTest() { assertEquals(2, 1 + 1); } } When I try to run as a JUnit test in IntelliJ 2017.2.3, I get: objc[32347]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8

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

和自甴很熟 提交于 2019-12-22 02:04:10
问题 The Maven 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: <properties> <junit.jupiter.version>5.0.1</junit.jupiter.version> </properties> <dependencies> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>${junit.jupiter.version}</version> <scope>test</scope> <

Best practice for looped JUnit test

你说的曾经没有我的故事 提交于 2019-12-22 01:27:46
问题 In a school assignment, I should write blackbox test for a method that returns true for a parameter < 80 and false otherwise. Currently my approach would be for (int i = 0; i < 80; i++) { assertTrue(someMethod(i)); } for (int i = 80; i <= 100; i++) { assertFalse(someMethod(i)); } However, this would require 100 seperate assertions. Is there a best/better practice method? If relevant, I'm using JUnit 5 but could switch to JUnit 4 if required (it's just a school assignment after all). Regards.

JUnit5: How to repeat failed test?

走远了吗. 提交于 2019-12-21 04:39:24
问题 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 = 40) How do I realize similar functionality with JUnit5? There's similar annotation in JUnit5, called @RepeatedTest(5) but it is not executed conditionally. 回答1: Ok, I took a little bit of time to

How to test Spring CrudRepository using @DataJpaTest in Spring boot 2.1.0.M4 using Junit 5

泄露秘密 提交于 2019-12-20 04:57:12
问题 I cannot test my spring crud repository using spring boot 2.1.0.M4 with Junit5 and @DataJpaTest . I am using the following spring crud repository interface. @Repository public interface DestinationRepository extends CrudRepository<Destination, String> { Optional<Destination> findCityCode(String code, String cityIsolci); } And this is my unit test class package com.test.repository; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions

Setting system properties when using junitPlatform

≯℡__Kan透↙ 提交于 2019-12-19 18:25:14
问题 I could not find out how to set system properties when executing JUnit 5 tests using Gradle. The standard test task could be configured as follows: test { systemProperty 'org.slf4j.simpleLogger.defaultLogLevel', 'warn' } However, the junitPlatform task seem to not have such an option. 回答1: Update: Please note that the junit-platform-gradle-plugin developed by the JUnit Team was deprecated in JUnit Platform 1.2 and discontinued in 1.3. Please switch to Gradle’s standard test task in Gradle 4.6

Spring 5 with JUnit 5 + Mockito - Controller method returns null

一个人想着一个人 提交于 2019-12-19 10:09:22
问题 I try to test a method named as loadData defined in MainController which returns result as a string. Despite that this method actually returns data when the web app runs on servlet container (or when I debug the code), no data returns when I invoke it from a test class based on JUnit 5 with Mockito . Here is my configuration: @ContextConfiguration(classes = {WebAppInitializer.class, AppConfig.class, WebConfig.class}) @Transactional @WebAppConfiguration public class TestMainController {

Properly set (system) properties in JUnit 5

元气小坏坏 提交于 2019-12-18 08:55:19
问题 We are using an approach similar to System Rules to handle (system) properties in our JUnit 4 tests. The main reason for this is to clean up the environment after each test, so that other tests do not inadvertently depend on possible side effects. Since JUnit 5 is released, I wonder if there is a "JUnit 5 way" of doing this? 回答1: You can use the extension API. You could create an annotation which defines your extension to a test method. import org.junit.jupiter.api.extension.ExtendWith;

Transaction roll back is not working in test case in @Nested class of JUnit5

杀马特。学长 韩版系。学妹 提交于 2019-12-18 08:09:08
问题 I use spring-boot, JUnit5, Mybatis. @SpringJUnitJupiterConfig(classes = {RepositoryTestConfig.class}) @MapperScan @Rollback @Transactional public class TestClass { @Autowired private TestMapper testMapper; @BeforeEach void init() { User user = new User(); testMapper.insert(user); } @Test public void test1() { // (1) success rollback } @Nested class WhenExistData { @Test public void test2() { // (2) rollback not working } } } (1) is working rollback. And the following log is output. 2017-05-26

How to create an HTML report for JUnit 5 tests?

你离开我真会死。 提交于 2019-12-18 04:09:41
问题 Is there already a possibility to generate an HTML report when JUnit tests were started via Gradle? Any hint or comment is appreciated. 回答1: UPDATE Gradle 4.6 provides built-in support for the JUnit Platform which allows you to run JUnit Jupiter tests using the standard Gradle test task which generates HTML reports out of the box. Answer for Gradle versions prior to 4.6 The JUnit Platform Gradle Plugin generates JUnit 4 style XML test reports. These XML files are output to build/test-results