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.

1
vote
1answer
25 views

AssertThrows not throwing exception when going through Java Streams

So I'm writing unit tests in which I'm testing capability to blacklist and unblacklist users (which is a feature in my code that is itself working fine). Here's a sample command that works as ...
0
votes
0answers
25 views

How is profile set automatically when running test cases?

I have a project which is dependent on a component developed by some different team; and that has declaration like this: @Component @Profile("!test") Class SomeClass { // code... } Now, when I ...
0
votes
1answer
15 views

create dummy request entity object to return while mocking testing request .post method

i am trying to mock a request entity objcet for testing a RequestEntity.post method. RequestEntity<CustomerInfo> body = RequestEntity.post(new URI(inquiryProperties.getEndCustomer())) ...
0
votes
0answers
8 views

PowerMockRunner Unable to determine method-name from description when delegating to HierarchicalContextRunner

I am trying to combine PowerMockRunner with HierarchicalContextRunner but I am having an error after the end of the "nested" tests @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(...
1
vote
2answers
31 views

mock a request entity call for unit test

i want to mock the request entity and response to test the method on the controller method, this code has been written by another developer and i am supposed to test it using mockito.i'm mocking the ...
0
votes
1answer
15 views

Mocking Spring Data Repository

I have a BeerRepository interface that extends JPARepository<Beer,UUID>. This interface contains this method. Page<Beer> findAllByBeerName(String beerName, Pageable pageable); In a ...
0
votes
0answers
29 views

How to run a specific unit test of a specific Test class of a specific Test Suite with Maven (JUnit 4)

I'd like to run a specific test routine called T20 which is in the class UploadTest which is part of the test suite TestSuite (Junit4). There is a @BeforeClass in my test suite that I need to run ...
-1
votes
0answers
9 views

In what way , or how Junit format can be beneficial for and tests/linter results as compare to JSON format [on hold]

I have some linter which provide results of tests/linter into common cli or json output so if I want to convert Json to Junit so how can it be beneficial for any linter ?
1
vote
1answer
29 views

Need assist with JUnit testing

I'm brand new to JUnit so I'm having a bit of trouble. I'm currently running JUint 4, and I'm trying to write a test that is specifically supposed to fail, yet it keeps passing as successful. I need ...
-3
votes
0answers
12 views

How to run Geb TestCases from windows command line?

I want to be able to run the geb testcases(SampleTestCase.groovy) from windows command line? I am having a hard time doing so, can anyone please help me out with this? Thanks
2
votes
0answers
26 views

How to add scalatest tags to a report?

My scalatest tests use tagging functionality and look like the following: "A test" should "test something" taggedAs (Smoke) in { .... } Is there a chance to add tags to junit report which is ...
0
votes
1answer
26 views

jUnit mock to test and code cover IOException

I have the following code snippet: try { Properties properties = new Properties(); properties.load(Thread.currentThread().getContextClassLoader() .getResourceAsStream("...
-1
votes
0answers
16 views

Just write primitive data and allow jvm to handle that data or do Integer.valueOf(primitive)

I am working with deprecation solution and got interesting or maybe easy confusion for pro coders. Here in method getDouble() we are creating new instance which is deprecated way and I changed into ...
2
votes
1answer
32 views

Debug Stream trace on functional code throws IncompatibleClassChangeError

When I tried to debug the stream in the code below via Stream Trace in IntelliJ, the debugger can't evaluate the foreach because the error below is thrown. I have no idea what it's about, the code by ...
0
votes
0answers
40 views

How is this possible? (Junit exception testing of linked list implementation

I am writing a LinkedList implementation which includes a previous function that returns the position prior to the one passed as an input argument. It should check whether the inputted position is the ...
0
votes
1answer
13 views

Why does JPanelFixture.comboBox().pressAndReleaseKeys() work with FEST, but not with AssertJ?

When trying to simulate input using AssertJ's pressAndReleaseKeys() for unit testing a JComboBox in a Java Swing program, I am not seeing the expected behavior. The program will most often hang on the ...
0
votes
1answer
28 views

Mocking an autowired object of base abstract class

I'm writing the Junit test case for a class which is extended by an abstract class. This base abstract class has an autowired object of a different class which is being used in the class I'm testing. ...
0
votes
1answer
14 views

maven not skipping tests with <skipTests>true</skipTests>

if I run maven on the command line: mvn clean install -DskipTests this actually works and it skips the tests, but if I do it in eclipse, it still always runs the tests <plugins> <!--...
-1
votes
1answer
46 views

How to create unit test to method that returns collection? [on hold]

I'm have a method: public List<Numbers> findNumbers(int[] array) { List<Numbers> list = new ArrayList<Numbers>(); for (int a = 0; a < array.length; a++) { for ...
0
votes
0answers
31 views

How to mock an object which hold others attributes(user defined pojo)?

I have a DataBinder class, which takes ModelObject in a constructor. This model class has 3 attributes, they are user-defined classes, which holds data. After mocking the user-defined classes, I am ...
0
votes
0answers
17 views

No qualifying bean of type repository when running test but not main application

I'm developing a Spring Boot application following TDD methodology. I've created the main classes (controller, service and repository) this way: import org.springframework.beans.factory.annotation....
0
votes
1answer
28 views

How to check if the view pager is at last element while writing unit in android

I was writing a junit test where I wanted to know whether the view pager is at the last element or not. How can I do this. Actually I am a begineer at writing unit tests. Thanks in advance :)
0
votes
1answer
35 views

Mocking Socket.getOutputStream() for testing Java

I have a piece of code I'd like to test - ServerHello connect( int version, Collection<Integer> cipherSuites) { Socket s = null; try { if(proxy!=null) ...
1
vote
2answers
82 views

How to continue execution after “NoSuchElementException” in Selenium (Java)?

I'm attempting to create an ArrayList of WebElements from this page: If all the elements are displayed, they're able to be added to the ArrayList just fine. ArrayList<WebElement> TodoArray = ...
0
votes
0answers
24 views

Junit XML to json format in Jroovy with XmlSlurper

I am trying to write a bridge function to convert XML data to the Json format below are the data I have the sample xml file is <testsuites> <testsuite tests="4" failures="4" errors="0" ...
0
votes
0answers
17 views

Testing RESTAPIs post method with MockMvc in Spring Boot

I keep receiving an InvalidMediaTypeException Heres my post method PostMapping("/notes") public Note createNote(@Valid @RequestBody Note note) { return noteRepository.save(note); } Here ...
0
votes
1answer
41 views

Mock Instant.now() without unsing Clock into Constructor or without Clock Object

I have below code in one of my method - ZonedDateTime current = Instant.now().atZone(ZoneId.of(AMERICA_NEW_YORK)); I want to mock current in junit test. I tried with java.time.Clock but for this ...
-1
votes
0answers
9 views

JUnit TestWatcher. succeeded() called on test failures

If I use the class watcher for JUnit, and the test fails either do to an exception or a failed assertion (a JUnit exception), in either case, the success method is called every time. JUNcore.runTest(...
-2
votes
0answers
37 views

How can I access member variable of method of a class under test?

Firstly I request to not mark it as duplicate of my previous question. It was incorrectly marked as duplicate and wrongly answered. Please read the question carefully and respond. Thanks..!! So I ...
0
votes
0answers
12 views

Does it exist a lint tool that is connected to the unit tests?

In our company we have developed an own tool that enforces company specific code rules. For example, we forbid using java.util.logging. This tool runs as unit test and specifies all failed cases as ...
0
votes
1answer
6 views

Android unit test failing on enumeration lookup initialisation

I tried writing a unit test and it fails on lookup.put(e.code, e); in this class : package com.toto.mbc.ui.enums; import android.util.SparseArray; import com.toto.mbc.R; public enum ...
-1
votes
0answers
19 views

Can I access member variable of method of a class under test? [duplicate]

So I want to access a member variable which has scope only inside the method which is to be tested during unit test of my controller class. So the code looks like below. @Controller public class ...
0
votes
1answer
15 views

Spring Boot Unit testing endpoint NullPointerException - and how to reach 100% coverage

I'm new to Spring Boot testing and I'm trying to test and endpoint. Following tutorials, I did this: @RunWith(SpringRunner.class) @ContextConfiguration(classes = SpringMiddlewareApplication.class) @...
0
votes
1answer
34 views

Only Need to write Junit for Integer.valueOf() in Java

So here is the thing, I found new Integer() in my code and which is deprecated now I planed to remove that pic of code (new Integer()) to Integer.valueOf() but as company rules I have to write the ...
0
votes
0answers
17 views

Mock is failing in If condition

In my controller, i am doing a validation check in if block using a validator class. Since validation code is not complete yet i just want to test that if validation was successful the response ...
1
vote
0answers
37 views

What test classes does `mvn test` execute?

I am using Cucumber, Java - Maven. I have class named TestRunner anotated with @RunWith(Cucumber.class) which is executed in command mvn test. But it also execute all jUnit methods marked with tag @...
0
votes
0answers
11 views

How will get UserTransaction in JUNIT [duplicate]

We are using EJB in our application. @Stateless(mappedName ="EventsDao") @TransactionManagement(value = TransactionManagementType.BEAN) public class EventDaoBean implements ...
0
votes
3answers
39 views

What should be checked in junit for a method that simply calls super.method()?

I have a junit method that only calls super.method(). What should be asserted in the junit for this method. public String foo() { return super.foo(); } Is asserting that the super.foo() is ...
2
votes
1answer
29 views

How can I generate mock data object for retrofit response automatically?

I am newbie to writing a test code as an Android developer. I am using the Kotlin and Retrofit in my android app. I have a retrofit interface like below: @GET("/3/movie/{movieId}") fun getMovie(@...
0
votes
0answers
48 views

Surefire Maven plugin: “Corrupted STDOUT by directly writing to native stream in forked JVM”

My JUnit tests are failing when running them through Maven and the Surefire plugin (version information below). I see the error message: Corrupted STDOUT by directly writing to native stream in ...
0
votes
0answers
18 views

JUnit SpringBootTest postconstruct and shutdown

I'm trying to test a SpringBoot application that self-registers with with a ServiceRegistry (eg. Eureka/Consul), and then deregisters on shutdown. The implementation simply extends pre-existing ...
0
votes
1answer
24 views

Unit tests on Caffeine LoadingCache implementation pass individually but one fails when run together

The unit tests (JUnit, Mockito) that I've written for my Caffeine CacheLoader implementation all succeed when I run them individually, but one of them fails when I run them all together. I believe ...
0
votes
1answer
23 views

PowerMockito mocking static method throws UnfinishedStubbingException

I've been reading a lot about this error and I cannot find a solution. This is my example code, you can copy it and launch it to reproduce the error. Main class: package example; import org.junit....
0
votes
2answers
29 views

How to create parametrized test cases in JUnit 4 and Kotlin for Android?

I need something similar to C# NUnit TestCase scenario with fixed expected results. I've already found this question on SO which has great solutions but they are for Java only and as suggested in ...
0
votes
2answers
36 views

JUnit avoid duplicate assertions

I am writing simple test cases for converting Entity to DTO and vice versa. The question is more about design. Is it acceptable to leave duplicates like in code below or is it better to create ...
0
votes
2answers
31 views

setUp() not being called in JUnit

For some reason, the setUp() method of my test class is not being called before my test method. import static org.junit.jupiter.api.Assertions.*; import org.junit.After; import org.junit.Before; ...
0
votes
0answers
25 views

Upgrading maven-surefire-plugin from 2.19.1 to 2.22.1 causes tests to not run

I have JUnit 4 tests that run with JUnit Jupiter (JUnit 5) using the vintage engine and maven-surefire-plugin version 2.19.1. [INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ jon-snow ---...
-2
votes
2answers
41 views

Java Spring Reactive Rest API Test Class Gives Error - Null Pointer Exception

I am trying to create a very basic rest API using the Spring Reactive programming and I wanted to also try the testing possibilities with Reactive Stack. However when I try to test the service ...
3
votes
1answer
26 views

Run jUnit tests per elements in a list

I have a large number of tests as described below: The expected value (y_position_expected) is hard coded to the jUnit tests. The tests send a value (x_position) to a method which does some statistics ...
-1
votes
1answer
25 views

How to mock if condition using JUnit?

I am trying to mock a method using mockito. How to mock if condition using mockito? Here is my code @Override public RemedyWrapperOutput createRemedyTicket(RemedyWrapperInput remedyWrapperInput) ...

http://mssss.yulina-kosm.ru