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.

0
votes
1answer
14 views

How to mock a method call in JUnit when the method is inside a base class and the testing method class extends it?

I need to write unit test in JUnit for a method, the method is inside class A and class A extends Class B. My testing method methodA() calls another methodB() which is inside class B. So how should I ...
1
vote
1answer
29 views

Kotlin inline class in JUnit tests

I am trying to understand concept of inline classes - they are a simple object wrapper of single property that is being inlined during runtime. That means, that the actual initialization of the class ...
-1
votes
1answer
27 views

pom.xml Maven configuration to run JUnit 4 + JUnit 5 Jupiter tests in mixed Java + Kotlin project

I cannot configure maven project successfully to run mixed JUnit 4 / JUnit 5 Jupiter tests for Java and Kotlin. I have no problems to configure Gradle (for instance this configuration works well for ...
0
votes
0answers
6 views

Make maven-invoker-plugin report in JUnit format

Is there a way to make Maven Invoker Plugin report in JUnit format in addition, or instead of its own report format? Alternatively, is there a tool to automatically convert Invoker reports to JUnit ...
-2
votes
0answers
18 views

How can I test this class? [on hold]

I have to test the class, but I am not a good tester in this case. How would you guys test this class? in relation to what? Please show me some code. Below is the method to test: public boolean ...
0
votes
2answers
12 views

Spring boot tests in memory db data not persisting between tests

I'm trying to do a test suite to check a @oneToMany relation i have I have a book_category and a book but my issue is that i have several small tests inside a test class and it seems that the db (H2) ...
-2
votes
1answer
21 views

How to write junit and mockito for below code, is it possible to mock C class?

Can some one help me to write the mockito for below code. public class B extends A() { public void dial() { C c =new C(); c.command(); } }
0
votes
0answers
28 views

What query can I run through BigQuery API to make bigquery Job object null for unit testing purposes?

I'm working on a Java application for a homework and I have to do unit testing of a method which runs a query on Google BigQuery. The method takes a string representing a query and outputs a Job ...
-1
votes
2answers
35 views

How can i test multiple java files with the same junit?

How can i test several .java files(that implements the same method in different ways) with one unit test? For example, i have a folder with different .java files(or different folders with the same ...
0
votes
0answers
7 views

Robolectric fails on command line but succeeds in Android Studio

I have a test where I use Robolectric which succeeds in Android Studio, but does not on the command line. I use Robolectric 4.2 and the test involves a cipher which I partially mock for this test. //...
0
votes
1answer
49 views

How to generate H2 embedded database during Mockito unit test?

I'm currently working on a springboot API where it has been decided that me and my coworkers will be using an H2 embedded database during development. The database is generating itself fine upon ...
5
votes
1answer
38 views

Junit cannot delete @TempDir with file created by Spark Structured Streaming

I created an integration test for my pipeline to check if the right CSV file is generated: class CsvBatchSinkTest { @RegisterExtension static SparkExtension spark = new SparkExtension(); ...
0
votes
1answer
33 views

JUnit Testing Null Pointer Exceptions

Test class: @InjectMocks private Topologic topologic; public Topologic() { histUtil = new HistUtil(); HistUtil.loadInstanceAndGroups(); } I am using the above code for a JUnit test case. ...
0
votes
0answers
9 views

Test with Spring annotations causes ClosedByInterruptException when executed in maven test run

I have a test class which looks like this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = TestClass.TestConfig.class) public class TestClass{ @Configuration @...
0
votes
2answers
38 views

Junit how to mock method return in test method?

I was getting a NullPointerException with following method's test but after comments I edited my code and now getting following error: org.springframework.beans.factory.NoSuchBeanDefinitionException: ...
0
votes
2answers
25 views

two times second ArgumentCaptor.capture() inside Mockito.when()

The issue is I have two argumentCaptors, and i need to use Mockito.when().then() two times, with this argumentCaptors.capture() in paramenets of method inside when(). But It run two times second ...
0
votes
1answer
27 views

Unit test throws exception

I am trying to unit test method that is responsible for returning the number of fat of given product. public class NutrientsCalculationService { .... double countFatNumberOfGivenProduct(...
0
votes
0answers
20 views

Spring parametrized JUnit Tests with Serenity

I'm looking for the solution how can i use spring integrations in serenity bdd frameworkk which is using JUnit runner. The issue is that i can't use methods in test data collection method because its ...
0
votes
0answers
16 views

Is there a way to set up an initialContext in a library just to run integration testing on some DAOs?

I'm trying to set up some integration test on a library that's only purpose is to store DAOs that other applications later access. However, I'm getting the following error: javax.naming....
0
votes
0answers
18 views

sbt assembly with Junit test fail

I am very new to scala and sbt. I wanted to run Junit tests with sbt assembly. I designed all my test an all run correctly with IntelliJ. When i try to build with tests, it always fails giving lots ...
0
votes
1answer
16 views

Testing Method Security, how to test @PreAuthorize(“#user.id != authentication.principal.id”)?

I am trying to test a method in my UserController named update which looks like the following: @RequestMapping(path ="/update", method = RequestMethod.PUT) @PreAuthorize("#user.id != authentication....
1
vote
3answers
48 views

How to wait for WebElement on a web page, which appers sometimes in random places while test execution?

I wrote an automated selenium based tests for a web application and they run perfectly with fast internet connection, but unpredictable behavior with less good connection. Web application was build ...
3
votes
1answer
30 views

[Easy|Power]Mock: make constructor.newInstance(…) throw an exception?

I want to make constructor.newInstance(...) throw an exception in a unit test. I'd like to check if the else-branch is reached in the following (dummy-)code: public <T extends IInterface> ...
-3
votes
0answers
30 views

Understanding assertEquals in JUnit Testing [on hold]

I'm new to programming and I was wondering what assertEquals does in this specific test. It says s1.toString(), however there is no s1 object, only an s object. Will this test come up as an error? @...
0
votes
0answers
32 views

How to write junit to test concurrency?

I am fairly new to Junit and Unit testing so please excuse if this qualifies as a bad question. I have to unit test my code for concurrency. I thoroughly understand I cannot ask someone to do code for ...
0
votes
1answer
26 views

jUnits taking too long due to heap memory getting full

For one of the projects I am working on, we have written jUnits that read requests from text files and then call methods. In the actual methods we are creating PDF reports, so the objects of Tables, ...
1
vote
2answers
45 views

How to write Junit test for this “FileNotFoundException”

How do I write a Junit test for FileNotFoundException, do I need to do something in the test so that my "numbers.txt" file is not seen? public void readList() { Scanner scanner = null; ...
1
vote
2answers
26 views

How to Mock an object that is not set to a variable

I am currently writing unit tests for legacy code. I need to Mock an object for a "doReturn" on a function call on that object. However, that object is instantiated on the same line it is being called ...
1
vote
0answers
21 views

RabbitMQ Java API queuePurge() method called on Qpid returns PurgeOK response with zero message count

I am integration testing a component that uses RabbitMQ client (amqp-client version 5.7.0) with an embedded Apache Qpid server object. When calling the Channel.queuePurge() method, the queue is ...
2
votes
1answer
27 views

JNA failing to load, UnsatisfiedLinkError, “Access Denied”

There are several similar questions, but I fear mine is different enough to be distinct. I am in windows 10 64-bit, using Eclipse 4.11 with OpenJDK 11, and am not using an admin account. When I run ...
1
vote
0answers
15 views

How to write a test case for Xframe response header

I wrote a code to resolve cross-frame scripting defect related to one of the servlet. code is as following utility class public class VulnerabilityUtil { public final static String ...
0
votes
0answers
13 views

Make requests for android data from test application

I am writing tests for android application. in one test I need to check, that android call log has some specific data. The problem is that tested application must not have "android.permission....
0
votes
0answers
14 views

Cucumber Test steps not showing in J-Unit while in console steps have run successfully

I'm currently trying to create my first Cucumber tests. In Java Eclipse I have created a 'Feature file' with the following content: Feature: Login functionality DemoQA.com Scenario: Verify if user ...
0
votes
1answer
47 views

How can I test my JwtAuthentication class using JUnit & Mockito? [on hold]

I can test my JwtTokenAuthenticationFilter class. How can I write the test cases of this class using Mockito & JUnit? I can Only test this class. I don't understand how I can mock the class. ...
-1
votes
0answers
18 views

How to generate Pact test automatically

I am new with Pact, I wonder if there is a way to write or automate the creation of Pact files ? instead of doing it manually? Or those who have already more experience, how do you do it? you write ...
-1
votes
1answer
34 views

How to verify a random number generation and provide a calculation

I have a Website https://www.ultimateqa.com/complicated-page/ on the website there is a form to fill in that has a Captcha which produces random numbers and asked the user to do the addition and enter ...
0
votes
0answers
12 views

How to write mockito test cases for rest API in spring boot..?

@RequestMapping(value ="/v0.1/getFySectionDetails", method = RequestMethod.POST) public ResponseEntity<?> getFyMonthlyPurchases(@RequestBody GstServicesRequestModel gstServicesRequestModel) { ...
0
votes
2answers
21 views

How can I use Mockito to mock a method of an instantiated class?

I need to write a test case for this CustomerEnrollmentSoapServiceImpl service. How can I mock the enrollExtStub.enrollExt() method @Service public class CustomerEnrollmentSoapServiceImpl implements ...
2
votes
1answer
41 views

Determine which fields of a POJO are being accessed in a code

I have a huge (parent) POJO which is being used in some component. The POJO has individual fields as well as nested POJOs as well. Is it possible to determine what all fields/ nested fields from this ...
0
votes
1answer
10 views

IntelliJ IDEA CE 2019.1: “JUnit Vintage” test section throwing “No runnable methods” when using `@RunWith(SpringRunner.class)`

When using the annotation: @RunWith(SpringRunner.class) Using IntelliJ IDEA CE 2019.1, I get a Junit Vintage section in tests, and it throws this exception: java.lang.Exception: No runnable methods ...
0
votes
1answer
15 views

org.springframework.http.converter.HttpMessageNotReadableException when running JUnit/Mockito Tests

Im running a JUnit test with Mockito in my Spring Boot application. I am mocking the repository which the controller is supposed to call. I am getting a HttpMessageNotReadableException when running ...
-1
votes
1answer
15 views

Selecting WebElements in JUnit @Test by calling method that defines WebElement paths

I'm creating a Junit test in Selenium that calls a method that defines WebElements that need to be selected during automation. When the Junit test is run it only launches the browser, goes to the ...
0
votes
0answers
17 views

VSCode not finding unit tests

For some reason my VSCode is not finding my unit tests in my "Test Explorer". It is able to find the class but not any of the methods in the class. I think that I must have something misconfigured ...
0
votes
0answers
39 views

JUnit theories, int sent to method changes to null

I have a jUnit theory and data point based test like this: @DataPoints public static List<Integer> location_map = TestCommons.mapTest(); @Theory public void testRelPositions(int cal) { ...
0
votes
0answers
16 views

Jenkins failing cucumber junit tests

I have a cucumber tests that all run successfully on my local but some of the tests failed when run with Jenkins stating unable to locate elements on all the tests that failed. I have re-run these ...
0
votes
0answers
11 views

Not getting coverage in Junits (Mocking StringBuilder and setting it to AddressModel)

I have a populator in hybris named SingleLineAddressFormatPopulator. I want JUnits for it. Having doubts how to mock as it involves String builder and a model class. I would be great if someone helps ...
0
votes
4answers
37 views

Writing unit tests with Random

I'm trying to test the behaviour of a method to generate a URL with a few parameters. The method makes use of a helper method which in turn makes use of new Random().nextDouble(). private static ...
0
votes
2answers
36 views

How to get which property of an object first mismatched in JUnit assertEquals?

I have a simple pojo class in the format as shown below. class PojoClass { property1; ... propertyN; @override public int hashcode() { //implementation } @...
0
votes
1answer
27 views

How to make this Year-2038-problem junit test work as expected

I am writing some code that will stop working after 19 January 2038 because of the Year_2038_problem when java Date overflows so i thougt i could create a junit test that starts failing in 2036 to ...
0
votes
1answer
11 views

TaskListener not invoked in unit test based on ActivitiRule

I am making use of ActivitiRule in unit test for process definition. I have implemented a TaskListener in the flow. But during test execution, TaskListener doesn't get invoked at all. Do I need to ...

http://mssss.yulina-kosm.ru