Questions tagged [junit4]

Version 4 of the popular Junit Java Unit testing framework

Version 4 of the popular JUnit Java Unit testing framework.

New features are the introducing of annotations to use the framework.

Use this tag only for question related to features provided by version 4. Use for general questions.

3828 questions
1
vote
0 answers

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:…
1
vote
1 answer

PowerMock `thenReturn` doesn't return expected data for mocked static method?

I am able to tun my test but it fails. The problem is, mocked method is still returning wrong data. This is my method that I want to test it: fun getTextByLanguage(list: List) : String { val deviceLanguage =…
Hesam
  • 46,136
  • 63
  • 203
  • 340
1
vote
1 answer

Can not Autowire bean in Junit

I am trying to unit test a Controller Class with Junit. However, when I try to autowire my PlayerRepository interface, which extends crudRepository, it gives this error: 2018-12-06 21:59:39.530 ERROR 8780 --- [ main] …
thetruth
  • 15
  • 4
1
vote
1 answer

Getting java.lang.Exception: Method xxx should have no parameters with jmockit:1.20, junit:4.12 with JDK11

I am using jmockit:1.20, junit:4.12 with JDK11. Earlier it was workign with Java 8 but now its not. The test class is: import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; import…
Ravi
  • 143
  • 2
  • 13
1
vote
1 answer

Correct way to fail a unit test from within a callback using Vertx Unit

Given the following unit test, which uses the Vertx Unit testing framework: @RunWith(VertxUnitRunner.class) public class VertxUnitTest { private Vertx vertx; @Rule public RunTestOnContext rule = new RunTestOnContext(new…
user1052610
  • 3,730
  • 7
  • 40
  • 79
1
vote
1 answer

Spring Testing with JUnit4 Runner does not work after trying different solutions

When autowiring my spring test class with the JUnit4 Test Runner the context startup yields the following exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.mypackage.TestClass': Injection of…
xetra11
  • 4,474
  • 6
  • 39
  • 98
1
vote
1 answer

404 on @RepositoryRestResource's url in JUnits

Something is missing or misconfigured for JUnits - I can't find. Getting a 404 instead of 200 in Junits. The application at http://localhost:8080/app shows the expected response. pom.xml
Anand Rockzz
  • 4,552
  • 3
  • 46
  • 58
1
vote
0 answers

How test coroutine correct?

Task is to clear the cache of images in the application. Decided to do it with the help of coroutines that the application does not hang. GlobalScope.launch { AppResources.appContext?.let { Glide.get(it).clearMemory() } } But don't really…
Morozov
  • 3,411
  • 3
  • 25
  • 48
1
vote
1 answer

Integration Test Asserting Each Element In A Collection

Considering an IT with Spring-Boot and JUnit that would test whether a collection returned from database contains all needed elements. What would be the best way to do that? To illustrate, consider a JPA class/entity such as the following: class…
Jaumzera
  • 1,874
  • 21
  • 37
1
vote
1 answer

Looper not mocked ViewModel MockitoJUnitRunner

I can't find a solution that will help me test my ViewModels. I keep reading that it's enough to add rule : @get:Rule var rule: TestRule = InstantTaskExecutorRule() but I keep getting : java.lang.RuntimeException: Method getMainLooper in…
1
vote
1 answer

Migration from Junit 4 to Junit 5 - Test case are getting skipped

I have migrated my junit 4 code to junit 5 with the below version dependencies. org.junit.jupiter junit-jupiter-engine 5.3.1
Sam
  • 600
  • 1
  • 6
  • 20
1
vote
0 answers

How to contribute a runner implemetaion

I have a JUnit test runner implementation that performs contract tests. I would like to contribute the code base to junit.org. Can anyone tell me how to make such a contribution? The implementation is used by several projects and is mature enough…
cWarren
  • 441
  • 5
  • 11
1
vote
0 answers

Android Room Database and 'Method getMainLooper in android.os.Looper not mocked'

I try to make unit tests for Android Room Database. I got error like that: Method getMainLooper in android.os.Looper not mocked when tried to make it thru with RxAndroid concept. A) Then i applied sample from 'How to unit test your RxJava code in…
1
vote
2 answers

Selenium Capabilities

I'm drowning in the Selenium documentation. What I've got so far is the ability to record a script in FireFox, export it to the new WebDriver format (JUnit4), open and tweak the test in Eclipse, then run it as a JUnit test in Eclipse. What I'm…
Cody Kiker
  • 11
  • 2
1
vote
1 answer

IntelliJ can not debug

i get following error when (locally) trying to debug by junit test in IntelliJ 2018.2.4: Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Unrecognized option: -XXdebug i think there is a…
mmoossen
  • 1,135
  • 3
  • 19
  • 28