Questions tagged [junit]

Popular unit testing framework for Java and Scala. The latest version, JUnit 5, supports rich annotation-based and parameterized tests. Consider using in conjunction with the Java or Scala tag to indicate your use case.

Filter by
Sorted by
Tagged with
0 votes
0 answers
18 views

Unit test also methods in Kotlin

I have a test function for the duplicate method of my service, and this method ends with a .also call, that runs after the return of the method. But my test isn't covering this. I have the following ...
Alice's user avatar
  • 11
0 votes
0 answers
11 views

PowerMock not using mocked "new" object

I have a Spring Boot project and trying to use PowerMockito to mock an object that is created inside the method. I have some code that is declaring a new Object that is extending an Abstract class: @...
SS123's user avatar
  • 3
0 votes
0 answers
9 views

how to mock errorDecoder

I have a class in my bff to decode errors from backend. Everything works fine, but I'm having trouble with unitTest in default case. My class have some part to get the error, that is not relevant for ...
cucuru's user avatar
  • 3,494
0 votes
0 answers
16 views

Spring Application context with parallel junit tests

I tried Junit 5.3 parallel execution for Spring Boot (2.7.12) integration tests. junit.jupiter.execution.parallel.enabled = true junit.jupiter.execution.parallel.mode.default = same_thread junit....
MaSEL's user avatar
  • 515
0 votes
0 answers
25 views

Offline IntelliJ installation and junit

I've seen similar questions but my installation has no outside connectivity. I've tried the recommendations in several posts I'll link below but my issue persists. I downloaded both junit and hamcrest ...
k_charles's user avatar
0 votes
0 answers
18 views

Kotlin tests with coveragge in intelij failed assertions

I have problem with intelij and coverage tests, when im running unit tests, without coverage, just by normally intelij run tests, all tests are success, but when i try to run it by tests with coverage,...
Karol Wolny's user avatar
1 vote
1 answer
35 views

junit 5 code/configuration reuse. should i use abstract test class or an extension?

junit 5 docs is using AbstractDatabaseTests but i remember recommended way for junit 4 was to use rules rather than extending classes.
duckydude20's user avatar
0 votes
1 answer
13 views

How to unit test onInitializeAccessibilityEvent in android

In my android application, I have 3 buttons where when the accessibility focus is cleared, I need to call a method. To achieve that, I'm doing the following fun setUpButton() { ... ...
enjoinslip's user avatar
0 votes
0 answers
11 views

CGLIB$SET_THREAD_CALLBACKS([Lorg.springframework.cglib.proxy.Callback) :

Some Junit Test cases are failing when running all test classes together but passing individually. **Caused by: java.lang.NoSuchMethodException: xxx.zzz$$SpringCGLIB$$0.CGLIB$SET_THREAD_CALLBACKS([...
Ashvinee Pawar's user avatar
0 votes
0 answers
30 views

Integration Testing using Junit Patch and Delete end point work but get does not

Using junit5, Java21 @Tag("IntegrationTest") @ExtendWith(SpringExtension.class) @WebMvcTest(controllers = ReasonsController.class) public class ReasonsControllerIntegrationTest { ...
Vaibhav Kumar's user avatar
0 votes
0 answers
9 views

Spring Framework class resolution with latest neo4j-ogm-core/neo4j-ogm-bolt-driver

I am using Java and Gradle to compile and test my project. Running gradle -v outputs the following: gradle -v ------------------------------------------------------------ Gradle 7.4.2 ---------------...
Blitzkoder's user avatar
  • 1,788
0 votes
0 answers
15 views

Quarkus Unit Test isn't reading the properties in application.properties

So I already have properties in my application-test.properties %test.feature.retry.enabled=true while in my application.properties: %dev.feature.retry.enabled=true then in my java code it looks like ...
Eve's user avatar
  • 43
0 votes
0 answers
11 views

how to mock an apache ignite query using mockito

I have a class and a test class, I am trying to test the result of an ignite cache query in my class by adding a mockito test in my test class. I am having a hard time understanding what needs to be ...
ruth's user avatar
  • 1
0 votes
0 answers
11 views

Display test results in Intellij in same order as defined in test method

When running Junit 4 tests on Intellij (Community 2023.2), I'd like the results to be displayed in the order the tests are defined in the test method. The results are displayed in a random order, ...
runningwild's user avatar
0 votes
1 answer
32 views

Mockito's reified mock method typing the mock as the superclass instead of generic type

I want to provide a simpler interface (utility method) to mock a construction of a class we often need mocked in many tests because it's constructed by a third party library. This class is generic ...
Gabriel Andrade's user avatar
0 votes
0 answers
15 views

Sonarqube missing blame files

I'm writing a program in java building it with Maven in an Intelij environment. I'm using pom.xln files. For some reason maven doesn't see my UnitTest files. I get a warnining : Missing blame ...
Gabi's user avatar
  • 1
0 votes
2 answers
42 views

How to unit test a XML document to string transformation method

public static String convertDocumentToString(Document xmlDocument) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer; try { ...
britney1994's user avatar
0 votes
0 answers
33 views

DBUnit behavior when checking view contents

I have a DatabaseUpdateRunner class that executes SQL scripts on an Oracle database. In my unit test, I'm trying to see if a view was created as expected and check the contents. public class ...
stripes137's user avatar
0 votes
0 answers
33 views

How to write JUnit for the following Code to read Azure Blob

Below is code implementation for reading an azure blob , i am getting exception java.io.IOException: Underlying input stream returned zero bytes for the line reader.readLine() in while condition. ...
lucky's user avatar
  • 367
0 votes
0 answers
31 views

my JUNIT code is not working for jsonObject

I have written below java class import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Base64; ...
snaik's user avatar
  • 1
0 votes
1 answer
19 views

How to use non-static @TempDir with custom @ConfigurationProperties during testing

I am working on a Spring Batch application which processes image files, where the path to the images is configurable using application.yml: files: image-path: /var/images I'm trying to use a non-...
helmi77's user avatar
  • 107
0 votes
0 answers
40 views

How to test lambda expression included private method using Mockito?

I want to test this code. public void send(String topic, Object value) { Optional.ofNullable(observer.get(topic)).ifPresent(handler::removeCallbacks); observer.put(topic, () -> send(...
Tahir Sultan's user avatar
-1 votes
2 answers
58 views

Constructing loop coverage for nested conditional loops in Java

I am currently learning about code coverage testing, specifically loop coverage, in Java. From context, loop coverage involves running a loop 0, 1 and >1 times. However, I've encountered a problem ...
Kenny Ynnek's user avatar
0 votes
0 answers
10 views

Dirties context upon TestRule

'''' import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; public class RetryRule implements TestRule { private int retryCount; ...
Mateusz Korga's user avatar
0 votes
0 answers
71 views

Mock WebClient for JUnit

How can I mock web client in JUnit test case so that I can test the following method that uses web client? public class Service { @Autowired private WebClient webClient; public Flux&...
unknown1101's user avatar
-2 votes
1 answer
44 views

Method threw 'javax.net.ssl.SSLException' exception

I have written a JUnit to test one of the method which calls below getAuthToken public String getAuthToken() throws URISyntaxException, IOException, InterruptedException { String formBody = String....
lucky's user avatar
  • 367
-1 votes
1 answer
28 views

Test case for my controller in the spring boot reactive web application gives errors

package com.example.demo4.controller; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test....
chan's user avatar
  • 3
1 vote
1 answer
38 views

UnitTest final UUID changes within the test if @BeforeEach#repository.save() is executed

I have an OrderRepositoryTest code below where I am trying to get the valid order by Uuid OrderRepositoryTest @DataJpaTest @ExtendWith(SpringExtension.class) @AutoConfigureTestDatabase(connection = ...
Mr. Kenneth's user avatar
0 votes
0 answers
23 views

Getting Browserstack Idle Timeout in Automation

Before launching the URL, I'm getting a timeout error. In error message says enter image description here Tried the resolution BrowserStack have provided. (https://www.browserstack.com/docs/automate/...
kavya M's user avatar
1 vote
1 answer
22 views

Mocking object in Cucumber

I'm trying to test my project using BDD and therefore im using Cucumber. The problem is, that when I want to test ProductController i can't properly mock my ProductService and i get ...
wojmaj22's user avatar
-1 votes
0 answers
21 views

how to solve the junit error which occured during running a springboot test application?

When I run the SqlcheckApllicationTests file as Junit I'm getting the below error .Please help me to rectify this error Image of the Error I tried to run SqlcheckApplicationTests file as Junit, the ...
Navya Hebbar's user avatar
0 votes
0 answers
18 views

Cucumber custom runner wrapper

I am trying to send an email containing a cucumber report after the cucumber tests have run and the report is generated, I was trying to use @AfterClass annotation with junit but it would execute ...
Aindriu's user avatar
  • 65
0 votes
2 answers
59 views

findById doesn't see the object from the mock

I am writing a test for the UserServiceImpl service. public User getUserById(long id) { Optional<User> optional = userRepository.findById(id); User user = null; if (...
ezulex's user avatar
  • 3
0 votes
0 answers
12 views

When the unit test started the application and started with hotswap agent, the initializePlugin reported a NullPointerException

When the unit test is run and the hotswap agent plugin is used, the initializePlugin reports a NullPointerException error when the application is started Caused by: java.lang.NullPointerException ...
rocco's user avatar
  • 62
0 votes
0 answers
58 views

Cucumber class ignored classparh for local runs. All test runs

Test project environment: java 17 junit5 cucumber7 maven 3.3.9 Runner class: @Cucumber @IncludeEngines("cucumber") @SelectClasspathResource("project/uss/as/play/test/features/smoke/...
Денис Кондратов's user avatar
0 votes
0 answers
10 views

No definition found for class:'com.subbu.unittestsample.TestUtil2'. Check your definitions

I am trying to write a unit test cases for one of the KoinComponent class but I am getting the below error org.koin.core.error.NoBeanDefFoundException: No definition found for class:'com.subbu....
subrahmanyam boyapati's user avatar
0 votes
0 answers
12 views

Android unit test generated jacoco coverage doesn’t contain original code coverage report

I have written the unit test codes and the Android.bp build file with “instrumentation_for” attribute targeting the indicated app to test, after I use the command “EMMA_INSTRUMENT=true ...
Naughtybeds's user avatar
0 votes
0 answers
8 views

How to start Appium server programmatically before the first scenario executed? (Using Cucumber and JUnit)

I want to start Appium server before the first scenario and then after the last scenario is executed, I want to close it. But I cant do it... Currently it starts the server before each scenario, and ...
emnznlg's user avatar
  • 11
0 votes
1 answer
34 views

GItLab CI - Maven run test disabled tests with JUnit 5

I tried to run CI pipeline on GitLab, but all time maven goal "test" is failed. Maven runs disabled tests by @Disable annotation. This tests for not implemented yet functionality, and as ...
Ilya Zhukau's user avatar
0 votes
0 answers
45 views

CP Subsystem waiting for members forever

when im trying to run my junit integration tests i get: CP Subsystem is waiting for 7 members to join the cluster. Current member count: 1 In a loop forever. I have no clue where it comes from and ...
Albert Albatros's user avatar
0 votes
0 answers
37 views

How to test flows in ViewModel

Should I implement some fake repository, and based on it make tests, or there is some better way? I've have read some articles about testing, but seems like most of them have their 'own method' to ...
fgregerg's user avatar
0 votes
0 answers
33 views

How do I return an error within Thruth library when writing down tests?

I'd like to ask you, whether this approach is valid for test: Let's say we have database, where we have a table that contains id, and name. I'd like to write some test which should return error. Here'...
fgregerg's user avatar
0 votes
0 answers
10 views

How to find RequestConfigCallback sockettimeout from Junit test of RestClientBuilder?

I have the following code in creating a RestClientBuilder where I set a custom socket time out: public ConnectionBuilder() { RestClientBuilder builder = RestClient.builder(new HttpsHost(host,port,...
shaselai's user avatar
0 votes
0 answers
32 views

Is there a way to change the classname in the junit report while using playwright?

after I ran playwright tests, junit test report is generated as shown below <testsuite name="/somefile.spec.ts" timestamp="...." hostname="chromium" tests="3"...
thanuz's user avatar
  • 1
0 votes
0 answers
17 views

Gradle - Print test summary on completion of all tests

I am currently using this answer to output detailed information of all tests as they run. Whilst I appreciate the level of detail that I can now see in the console as my tests run, what I would really ...
Matthew Layton's user avatar
0 votes
0 answers
10 views

Assert on Flux List which changes list contents while iterating

I am having a flux created from list of object type. While iterating on List I am calling 2 methods updateCashCT and updatePaymentDocument for which item of list which updates the list items. Since I ...
Loren's user avatar
  • 332
0 votes
0 answers
18 views

How to return different values with the same method call in the same class in a loop?

I am looping over a list table names to do the following Call describe table to check if the table exists If the table doesn't exist, throw ResourceNotFoundException. Call createTable method to ...
Mojo jojo's user avatar
0 votes
1 answer
16 views

Spring Batch Unit Test triggered entire batch execution

I am implementing a new batch with spring batch. But I am facing some issues when I tried to run junit test. Problem: I only want to test some functions inside the service class, but when I run it, ...
William's user avatar
  • 31
0 votes
0 answers
27 views

Spring boot Junit tests fail : I/O error on GET request for "http://localhost:8080/v1/pr": Failed to connect to localhost/[0:0:0:0:0:0:0:1]:8080

I am writing Junits for my spring boot code. I am unable to mock and test RestTemplate. I went with SpringBootTest as an integration test approach instead of simple unit test, as the resttemplate was ...
user0123812's user avatar
0 votes
1 answer
16 views

Mocking a gradle project in MockK doesn't call the stubbed method

I am writing a unit test in kotlin using JUnit and MockK to test my custom Gradle task. open class CopySourceTask @Inject constructor( private val config: MyCustomExtension ) : DefaultTask() { ...
newbie's user avatar
  • 1

1
2 3 4 5
558