Skip to main content

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
-1 votes
0 answers
24 views

doAnswer Mockito: Behaving strange and not verifying the mocked listener [closed]

I am trying to test the API call method, since this API is final I can not extend and create Test Doubles, so I have used Mockito to stub the functionality after initializing this API, I created Test ...
Nadin Martini's user avatar
0 votes
0 answers
15 views

Stubbing error while mocking WebClient using Mockito

Based on answers to previous questions like these, I am trying to mock WebClient in a unit test. Please note that I don't wish to use WireMock or MockWebserver. source method: public class ...
Kaliyug Antagonist's user avatar
1 vote
1 answer
23 views

I cant init my webclient in a test with mockito

I'm working on a project with java spring boot 2.x and java 1.8. In my pom i got the dependencies of junit 4.13.2 and mockito 3.12.4. When i try to run my test i got the problem that my setup function ...
Juan Federico Di Leo's user avatar
0 votes
0 answers
38 views

How to mock Files API from java.nio.file.*

I am using Java nio API and have a below code, but unable to perform mocking on the below code. Path path = Paths.get(filePath); long sizeInBytes = Files.size(path); long recordCount = 0; try (Stream&...
Prateek's user avatar
  • 11.4k
0 votes
1 answer
19 views

JUnit 5 - Migration - Custom test annotation no longer detected?

I had the following custom test annotation that worked in JUnit4 that IntelliJ and JUnit no longer wants to recognize: @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE }) @Retention(RUNTIME) ...
David S's user avatar
  • 177
0 votes
0 answers
29 views

pytest failing to generate xml correctly

Unable to generate junit xml file correctly, after a failure generation of the file stops and no further tests are executed. The command works without the junit argument. I have also tried adding '-...
James's user avatar
  • 597
0 votes
1 answer
44 views

SimpleAgedCache: Why can't I get my SimpleAgedCache to pass its tests?

I'm new to coding and programming, and I found an interesting SimpleAgedCache exercise on GitHub that uses JavaScript. I feel like I've done the correct coding, and the exercise should pass its tests. ...
Charles Galicia's user avatar
-1 votes
2 answers
53 views

How to write a unit test with a controller method that has protected code in it [duplicate]

I am trying to write a unit test for the following controller: @RestController @RequestMapping(value = ENDPOINT_URL) public class MainController extends RestControllerBase { MainService ...
aCarella's user avatar
  • 2,474
-1 votes
0 answers
33 views

How to mock a method call which is private and static? [closed]

TestThisMethod is the class and command Store is the method invoked from useCommandStore. I want to mock commandStore which is private and static, when and then of JUnit is not working here. Class ...
Henry Passion's user avatar
-3 votes
0 answers
34 views

In Springboot, Junits [closed]

In Spingboot, I am writing Junits for services and I am getting error as "The method findByLine1(String) is undefined for the type ExampleService". Why am I getting this? How to slove this ...
Hema's user avatar
  • 1
-1 votes
0 answers
500 views

Test cases failing and getting NoClassDefFound Could not initialize class XXX after upgrading Maven to 3.9.6 version

Test class `@BeforeEach public void initResource() { serviceLocator = mock(ServiceLocator.class); service = mock(Service.class); resource = new MappedDefaults(serviceLocator, service); ...
Priya Jain's user avatar
0 votes
1 answer
59 views

Asserting availability of SubTypes of T

I would like to assert whether every element of an array is a sub type of a particular class. So I wrote a helper like this: private <T> void assertContainsAllSubtypes( List<? ...
bdhar's user avatar
  • 22.6k
1 vote
2 answers
43 views

Is it advisable to repeat an integration test that is used in more than one method?

I'm developing a project. This project has a repository (UserRepository) which is referenced by other parts of the project, I want to know if I have to test the repository method each time it is ...
Mateus Fonseca's user avatar
1 vote
1 answer
22 views

Java unit test failing due to null KeyHolder

I'm creating new unit tests for an application and I'm stuck because the KeyHolder is not returning a valid object. For context, here are my classes: ScriptDao class: @Repository public class ...
Thiago Apolinario Billieri's user avatar
0 votes
0 answers
10 views

The user is experiencing an error in their Junit program, despite using assert-equals with two integer numbers

I have used the Assert Equals (Expected, Actual) method which takes two integers value and stores its sum in the Actual variable. I am putting my code below. public class CalcTest { @Test ...
Tushar Dharaiya's user avatar
0 votes
0 answers
21 views

Junit error Can't load log handler "1catalina.org.apache.juli.AsyncFileHandler"

Getting below error while running junit. Can't load log handler "1catalina.org.apache.juli.AsyncFileHandler" java.lang.ClassNotFoundException: 1catalina.org.apache.juli.AsyncFileHandler java....
Ast's user avatar
  • 163
-1 votes
0 answers
20 views

java.lang.RuntimeException: Could not setup GlassFish Embedded Bootstrap

I have a deployment class for integration tests in my project that is inheriterd by every test class. This class is annotated by: @ArquillianSuiteDeployment @RunWith(CustomArqullianRunner.class) I'm ...
Albert Albatros's user avatar
0 votes
0 answers
26 views

In Java, using Mockito fails to initialize MockMaker plugin

When I try to run this code: package __6__240703.test.user_repository; import static org.mockito.Mockito.*; import static org.junit.jupiter.api.Assertions.*; import __6__240703.main.user_repository....
Tomer Sagi's user avatar
0 votes
1 answer
45 views

junit 5 runs specific cucumber feature twice

Running Cucumber with JUnit 5 works ok as long as all feature files are run. @Suite @IncludeEngines("cucumber") @ConfigurationParameter(key = Constants.FEATURES_PROPERTY_NAME, value = "...
tbeernot's user avatar
  • 2,572
0 votes
0 answers
26 views

mockito, mock new file or mock file.exists() [duplicate]

Prerequisite: Powermockito cannot be used and the original code cannot be changed. how to let File file = new File("xxxx"); file.exists() returns true. public void testFile(String path) { ...
user25724873's user avatar
0 votes
0 answers
22 views

How to pass a Junit Test for a Primefaces FileUploadEvent

i have a doubt about how to pass a JUnit test for a Primefaces FileUploadEvent. The methods is this: public void cambiarLogoCrear(FileUploadEvent event) { cambiarLogo(event, false); } private ...
Blrackerd's user avatar
0 votes
0 answers
43 views

When I perform spring-boot unit testing, the spring datasource is repeatedly initialized

I'm using Groovy + Spock to perform unit testing for a Spring-boot project. I have two test classes, Test Class A and Test Class B. These two test classes are independent and have no dependency ...
Mike Wu's user avatar
0 votes
1 answer
38 views

Yet another "No tests found" question (testDebugUnitTest). Did I miss a dependency somewhere? Trying to use JUnit5

I've made my first android app (a very simple button tapper) and am currently trying to create test files for it. I've been following the YouTuber Philipp Lackner and have gotten by pretty well ...
zecuse's user avatar
  • 167
-1 votes
1 answer
37 views

How to unit test Mapper provided by MapStruct?

I want to unit test my MapStruct mappers, if that is a thing, should I use Mockito, or can I just call mapper = new UserMapperImpl();. UserMapperTest.java class UserMapperTest { private ...
Davido's user avatar
  • 95
0 votes
0 answers
26 views

Maven surefire overwrites the logs for flaky tests on rerunFailingTestsCount

I'm using maven-surefire-plugin to rerunFailingTests for the failing tests. If the test fails in first attempt and pass on the later attempts, the logs(*.txt, *-output.txt) from the /target/surefire-...
KGP's user avatar
  • 350
0 votes
0 answers
27 views

Junit Mockito Testcase for Rest API controller class taking boolean as path parameter

I am new to Junit Mockito testcase. I am trying to write REST API controller class .But facing some issue.Can someone please help me on writing the test case. @RestController @RequestMapping("/...
Deepak's user avatar
  • 11
0 votes
1 answer
48 views

How to use class member variables inside Junit-Mockito tests

class MyClass { MyErrorServiceList myErrorServiceList; // myErrorServiceList is initialized by some complex method calls public boolean processErrorServiceList() { if (...
Henry Passion's user avatar
0 votes
0 answers
20 views

Gradle junitXML system-out at wrong position

I use Gradle and Appium for integration tests. I want to upload the generated junit.xml file to an external tool. For this, I need a specific format for my XML file. Currently, 'system-out' appears ...
Kleifker's user avatar
0 votes
1 answer
36 views

Junit Mockito testcases for Service Layer

I am facing issue while writing junit mockito testcases for the below service layer class. Can someone help me writing the test cases for me. public class BigQueryServiceImpl implements ...
Deepak's user avatar
  • 11
1 vote
1 answer
69 views

Use custom Dockerfile with JUnit testcontainers for OpenSearch

I'm trying to use a JUnit test container for OpenSearch, in Kotlin, with the Spring Boot framework. (Enough qualifiers?) I've been able to get it mostly working, roughly like this: class ...
Crell's user avatar
  • 524
0 votes
0 answers
12 views

Create and write to a real file in JUnit test case

I have a unit test case in Android where I want to create a new file and write data to it. This file needs to be manually analysed later so cannot use TemporaryFolder(). Is there any way to create a ...
Bigbrain Ammamma's user avatar
0 votes
0 answers
29 views

JUnit test to compare specifications

I have a method that creates a Specification from a user role. I am trying to create a junit test to see if the output is well created. In this example I am providing, the user with an IP role, and ...
Robin J's user avatar
  • 33
-1 votes
0 answers
44 views

Why is the mock object being null in testing an Abstract Class's Concrete Method

I have an Abstract class CustomerHelper with a concrete method saveCustomerWithoutPF(). I have mocked an object that it calls (from a private method) and returned a value when (using Mockito.when) ...
Yadhu Krishnan's user avatar
0 votes
0 answers
33 views

I created a test case method named 'testRegisterCustomerSuccess,' but it encountered issues related to JPA queries

I have a method named registerCustomer in a service implementation class. I created a test case named testRegisterCustomerSuccess for this method in a class named UserServiceImplTest, where I mock ...
Prince Lathiya's user avatar
0 votes
1 answer
28 views

Error occurred prior to updating JUnit 4 to JUnit 5

Before the update, don't run my class RunTest, get a error in execution package automation; import org.junit.FixMethodOrder; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; ...
Lucas Tenório's user avatar
0 votes
1 answer
21 views

Junit for the elastic search ParsedFilter

I am trying to cover Junit for elastic search ParsedFilter. Code: private void returnDeviceColumnValues(List<String> uniqueColumnValues, NativeSearchQuery searchQuery) { SearchHits<...
bharathi's user avatar
  • 6,161
0 votes
0 answers
24 views

Android test class with time delay

I'm working on an IdleHandler class in my Android app to handle inactivity. The class looks like this: class IdleHandler { object TimerConstants { const val ...
James Ostevik's user avatar
0 votes
1 answer
54 views

Testing Routes with Spring Boot und JUnit

Hello I really need help testing my routes (if that is even a good practice). Setup: Spring Boot JUnit Vaadin I want to test my protected routes, which only admins should be able to get access to. ...
chris's user avatar
  • 1
-1 votes
1 answer
32 views

Mocking the new instance creation call inside a void method without using PowerMock

I have a class where inside a void method it does a new instance creation public class BaseDao { protected void setDataSource(DataSource dataSource) { this.defaultTemplate = new ...
Plainsage's user avatar
  • 145
1 vote
2 answers
104 views

Testing Dispatcher IO and ViewModelScope in Unit Tests

I'm trying to test some code in my viewmodel. I'm trying to make two network calls with dispatcher async, but haven't figured out how to test. This is a simplified example of what I'm essentially ...
keyboard_user's user avatar
0 votes
0 answers
61 views

How to throw exception with super constructor been mocked

I have an exception class public class FooStudioException extends SpamException { public FooStudioException(String message, String localizedMessage, Throwable cause) { super(...
Abhijit's user avatar
  • 63.3k
0 votes
2 answers
76 views

Running a Single Parameterized Test with Maven in JUnit 4

I'm trying to run a specific parameterized test method (xyzIT#testTaskRestarts) from a JUnit 4 test class using the Maven Surefire Plugin, but I'm encountering issues. With the base command being set ...
Sangeet's user avatar
  • 1,026
-3 votes
1 answer
63 views

My when(...).thenReturn(...) is not working [closed]

I'm making some test but my mocking is not working. This is my test class. @UnitTest @RunWith(MockitoJUnitRunner.class) public class ResendMailingStrategyUnitTest { @Test public void sendTest(...
Nicolas Villacorta's user avatar
0 votes
0 answers
22 views

Unit testing class with flow collection in init

How can I best go about unit testing flows that are collected in a class's init function? The only solution I've come up with so far requires hard-coded delays. Consider a sample implementation of a ...
Henrik Klev's user avatar
0 votes
0 answers
28 views

Mock WebClient webflux bean with Qualifier

I have the following scenario: A config class with two WebClient beans with different names public class WebClientConfig { @Bean("bean_1) public WebClient getWebClient1(WebClient.Builder ...
Gabriel García Garrido's user avatar
0 votes
1 answer
67 views

Unable to pass multipart file through mockMvc

I am writing junit test for my request method. Im using mockMvc to trigger the rest request. When I run my test I get the error java.lang.NullPointerException: Cannot invoke "org.springframework....
manjosh's user avatar
  • 564
2 votes
1 answer
81 views

Cannot run explicitly tagged test only in Kotest

I have a spring boot project which uses kotlin version 1.7.0. My pom looks something like below. <properties> <kotlin.version>1.7.0</kotlin.version> ... </<...
Risalat Zaman's user avatar
0 votes
0 answers
94 views

Kotlin Coroutines Test: UncompletedCoroutinesError - Test Coroutine Not Completing

I'm encountering an UncompletedCoroutinesError while running a Kotlin coroutine test. The specific error message is: kotlinx.coroutines.test.UncompletedCoroutinesError: After waiting for 1m, the test ...
Kotiswar Kaithepalli's user avatar
0 votes
1 answer
35 views

Configure xunit output of Testem in Ember.js

I use Ember 5.6.0. Running ember test --silent --reporter xunit > ember-test-result.xml outputs an XML with the following content: <testsuite name="Testem Tests" tests="439" ...
crusy's user avatar
  • 1,492
0 votes
1 answer
27 views

No error message provided by the last invocation of @RetryingTest

I have a test like this (language is Kotlin): @TestInstance(TestInstance.Lifecycle.PER_CLASS) class MyTest { private var i: Int = 0 @RetryingTest(3) fun go() { Assertions....
Boris's user avatar
  • 1,116

1
2 3 4 5
562