Category "junit"

Difference between @Mock, @MockBean and Mockito.mock()

When creating tests and mocking dependencies, what is the difference between these three approaches? @MockBean: @MockBean MyService myservice; @Mock: @Mock

JUnit GUI doesn't show executed test methods

I run a test class, the outprint in console is correct, but the list of the @Test methods doesn't appear in the JUnit tab: How to fix it? Does the asterisk o

Mock ResultSet with Mockito

How to mock the resultset? In the test class trying to mock the resultset as below but, when trying to test getting error as UnnecessaryStubbingException at s

Spring Boot Kotlin Mockito @MockBean dependency throws IllegalStateException null on method call

I am relatively new to Spring and Kotlin. I ran into this problem and it does not seem that there is a comprehensible (for me) explanation anywhere on the Inter

Maven not running JUnit 5 tests

I'm trying to get a simple junit test running with maven but it is not detecting any tests. Where am I going wrong? The project directory Project -> src ->

Spring Email with Greenmail: Authentication Credentials Invalid

I am trying to write test code for Spring Email using Greenmail. This works perfectly with 1.5.5 version of Greenmail, however when I try to update the version

How to redirect JUnit testing to the console in Eclipse?

I am a blind screen reader user and have a problem with JUnit in Eclipse. The results of tests passing or failing is represented as far as I understand visuall

Why isn't @DisplayName working for me in JUnit 5?

For some reason, I'm really having a hard time getting display names to actually be respected in JUnit 5 with Kotlin. Here's a test file I created for the purp

Junit Parameterized Constructor - Wrong Number of Arguments

I am trying to build a parameterized Junit Test in order to test each occurrence of a LinkedHashMap within an ArrayList of LinkedHashMaps. This is because each

JUnit testing got initializationError with java.lang.Exception: No tests found matching

When running JUnit testing , it gave an initializationError: No tests found matching. Like this: prodapi-main-junit initializationError(org.junit.runner.manip

How to write Unit Test for below Exception Handler method using mockito?

@ExceptionHandler({ ConstraintViolationException.class }) public ResponseEntity<Object> handleConstraintViolation(ConstraintViolationException ex, WebRequ

Mockito argument matcher and hibernate lazyinitialization

I've created the following captor: public class CompanyOwnerMatcher extends ArgumentMatcher<CompanyOwner> { private String uuid; CompanyOwnerMa

How to properly remove a dependency in a Maven project

I have a Java Maven project where I have some dependencies defined in the pom.xml file. Recently I decided to move from Junit to TestNG so I deleted the Junit d

Android Studio cannot resolve org.junit

I am using JUnit tests in Android Studio 1.2.2. The tests run without a problem. The only thing that puzzles me is that Android Studio cannot resolve the actual

Spock TestEngine with ID 'spock' failed to discover tests

When I was running unit test with spcok,An exception appears: Internal Error occurred. org.junit.platform.commons.JUnitException: TestEngine with ID 'spo

Why does Android Studio say "Test events were not received"?

I'm trying to unit test in my android application, and this is the simple test tutorial what i'm doing. import static org.junit.Assert.*; import org.junit.Test

How to use MockRestServiceServer with multiple URLs?

I need to configure multiple expectations on an instance of MockRestServiceServer. The expectations are for two different URLs: Call URL #1 Call URL #1 (for a

How to link @BeforeEach method with specific @Test methods (Java, JUnit)?

For example we have 2 classes: BaseTest and Test. Test extends BaseTest. BaseTest.class contains 2 methods with @BeforeEach annotations. @BeforeEach void setU

How to mock Base64 in Android?

I am writing a Unit test for a class that uses android.util.Base64 and I get this error: java.lang.RuntimeException: Method encode in android.util.Base64 not m

Test a method that use a spring service

I have a problem testing a method in Java (I use jUnit 4) and this method to test make a call to a repository and should throw an exception if something is wron