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
0answers
6 views

How the latest JUnit5 installing and configuring in Windows environment

How the latest JUnit5 installing and configuring in Windows environment.Its completely different from previous version(jUnit4). The older version is composed of single jar file. After extracting the ...
0
votes
1answer
31 views

How to mock Autowired objects(java) and inject inside to a spy object in Spock

How I can inject mock objects into a spied instance in Spock? Example: TestClass class Service { @AutoWired private Util util; public void testMethod(int a, int b) { int ...
1
vote
2answers
31 views

Using @Select for query data, but got 'Invalid bound statement (not found)'

I have a project using spring+mybatis. I want to using @Select for querying data, but got error log like "Invalid bound statement (not found)". I find a article in mybatis's Chinese official website, ...
0
votes
1answer
11 views

How to write RXjava 2 test for a behavior subject abstracted behind an interface

I have a behavior subject that will be DI. I then have different interfaces, that subscribe to that object. Below is a super simple one I am writing so that I can mostly restrict access to the ...
-1
votes
0answers
22 views

The constructor Kinosaal(int, Kino, int) is undefined

I have to do a cinema management system. But I have a problem with one constructor. The error message (The constructor Kinosaal(int, Kino, int) is undefined) only is shown when I try to use ist in ...
1
vote
2answers
32 views

Verify if the correct data type using serialization

I have a POJO provided below, @Setter @Getter public class OrderDto extends BaseDto { @JsonProperty( "products" ) private final List<String> products; @JsonProperty( "...
1
vote
3answers
55 views

writing unit test cases for an interface which has methods without arguments

I have an interface which has a method without arguments public interface HealthStatus { Integer healthCheck(); }� The implementation is as below @Override public Integer healthCheck() { ...
1
vote
1answer
23 views

writing negative unit test cases for controller classes :springboot

Is there a way i could write some negative test cases for the controller class @RestController @RequestMapping(value = "/health") @Api(value = "EVerify Health check API", description = "Health check ...
-1
votes
1answer
50 views

How can I compare two elements in a same array?

I want to write the test case with Junit for my ParOfDice class. But I do not know, how can I compare the elements of the same array. Not two differents array. public class Wuerfelpaar { // ...
0
votes
1answer
29 views

Gradle tests fail locally, but succeed on CI servers

I have a Gradle Java project set up with JUnit unit testing. There are some tests that are supposed to fail. They do so on my machine, but it succeeds without errors on CI servers. The natural first ...
0
votes
1answer
24 views

How to write test case for Spring boot Application class with properties dependency - Could not resolve placeholder

I followed the below StackOverflow page and wrote test case for Application class How to test main class of Spring-boot application When I run my test case I get the following error Caused by: java....
0
votes
1answer
18 views

How to configure Junit in Jenkins with Maven

I have a maven project with many Junit tests. It's actually a regression test repository. So now I want to build a Jenkins job to run the regression test automatically when building instead of ...
0
votes
1answer
12 views

How can I specify a schema name for DbUnit to do the insert into?

I'm using DBUnit to insert data (dumped from a Postgres DB) into SQL Server, but want to do the insert into schema "rules", not the default "dbo" schema: Class.forName(net.sourceforge.jtds.jdbc....
-2
votes
0answers
16 views

EmbeddedKafka vs KafkaTestUtils [on hold]

Should I use EmbeddedKafka or KafkaTestUtils for unit testing on kafka streams? Please let me know the comparision/usage of these two. And when should we use what? Planning to write junits on kafka ...
-2
votes
0answers
14 views

Unable to mock ApplicationContext

I am unable to mock ApplicationContext. private CommonAppContextProvider commonAppContextProvider; ApplicationContext applicationContext = mock(ApplicationContext.class); when(...
0
votes
0answers
15 views

Running powermock + mockito on java 11 http client

I am trying to run powermock + mockito with Java 11 for unit test cases. I am using the below versions: testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'org.mockito', ...
0
votes
0answers
65 views

JVM version conflict prevents Eclipse / Jetty from functioning properly

I'm experiencing the following conundrum while using Spring Tool Suite with the following coordinates: Version: 3.9.5.RELEASE Build Id: 201807031734 Platform: Eclipse Oxygen.3a (4.7.3a) on MacOS ...
0
votes
0answers
20 views

#TestNg #JUnit #Maven #Selenium

Immediately after removing Junit from the pom.xml , an error is coming to my POM project. a. I have removed Junit from pom.xml but it is still showing in the src folder. The error sign should be ...
0
votes
1answer
37 views

Mockito how to test findById() returning an Optional

I'm stuck trying to test the findById() method from the CrudRepository. This method returns an Optional and I can't figure out how to return it, right now its giving me a NullPointerException. My ...
0
votes
1answer
24 views

Testing starter with Springboot+JUnit

I have a custom library (a starter) created with SpringBoot. So, it doesn't have main method or @SpringBootApplication annotated class. I want to test this starter functionality with JUnit. I have ...
-1
votes
0answers
16 views

Unable to get JUnit4 and JUnit5 tests to run together - maven, surefire [duplicate]

UPDATE This is NOT a duplicate question. The quoted duplicate answer is something that I had reviewed already. The issue for me was the version of the junit-vintage-engine that I was using 5.4.2 did ...
0
votes
0answers
21 views

Cannot run tests from terminal with Maven [duplicate]

I have a package with some tests in it. The structure looks like this: I navigate into the test folder and try the following: home/me/cust/tests/test$ mvn clean test [INFO] Scanning for projects... [...
-1
votes
1answer
26 views

Is there a way for a JUnit test to pass iff method implementation is correct AND recursive?

I am setting up some practical exams and require implementation of certain methods to be recursive. Is there a way for the JUnit test to pass only if the implementation of the method is recursive (and ...
0
votes
0answers
10 views

How can i make a configuration for my test cases that will run selected methods or a group of classes in android studio?

For example if i have the following class. I want to make a configuration which will run only insert and update and one configuration which will run select all and delete all. Is there any way i can ...
0
votes
0answers
17 views

Mocking subsequent calls to a method with one of the two argument same

In a method I need to unit test, following is the situation: Predicate<MyClass> predicate1 = (MyClass myClass) -> myClass.getX().equals(SOME_VALUE); List<MyClass> targets = this....
0
votes
1answer
28 views

How to run code after test failure in JUnit5?

How can I run a function or a wrap-up code after a test failed in JUnit 5?
0
votes
1answer
16 views

2 variants for JUnit execution: TestRunner & JUnitCore

There seem to be two approaches for invoking JUnit tests from the OS command shell: java junit.textui.TestRunner <class-name> and java org.junit.runner.JUnitCore <class-name> When do ...
0
votes
1answer
20 views

How to unit test mongotemplate functions

I want to write unit test for mongotemplate function calls. I am not sure how to write that, I have seen instances of integration test case only on web. public Class customerById(String id) { ...
0
votes
1answer
47 views

How to see my scenario names in Test Result in Java

In the Test Result section, the class names appear as classMethod. I use the cucumber test library for tests. In the Test Result section, I want to see the "Scenario:" names that I have specified in ...
0
votes
1answer
13 views

Why does notNullValue() not compile when used with everyItem in Hamcrest

In Hamcrest the matcher notNullValue() can be used to check that a value is not null: String string = "Foo"; assertThat(string, notNullValue()); However, this pattern cannot be used for collections: ...
2
votes
2answers
31 views

JUnit How to assertTrue/Equals on a Optional and a object

How do I use assert.equals to test between a Optional and a Object? After debugging it shows the same values but my test still fails to pass. Returning error: at org.springframework.test.util....
0
votes
0answers
20 views

Is there a way to use surefire-plugin report with junit and cucumber?

I'm using Junit 4 to run Cucumber scenarios and surefire plugin to generate summary report, but my problem is that in the report each step from my scenarios reported as separate testcase, as a result ...
0
votes
0answers
16 views

Using Mockito to test deleting records from an HBase Table?

I am writing unit test cases for an offset management utility (table stores offsets of partitions along with their status, and I am fetching/updating when needed). To do so I need to mock a connection ...
0
votes
0answers
20 views

How do I get SonarQube to count spock/groovy unit tests?

I am trying to configure SonarQube to report an accurate count of the unit test cases in my repository, currently it is only showing the java jUnit test cases. SonarQube reports the java jUnit test ...
0
votes
1answer
29 views

Trying to run junit test and get the following error: unreported exception Overflow; must be caught or declared to be thrown

I'm not supposed to touch the code, simply run junit tests on it. I get the error whenever I run the insert method. I tested isFull (with assertFalse), so the exception shouldn't be thrown? I get ...
0
votes
1answer
37 views

How to implement a client that has to login in every 30 min?

I am writing an application which uses the JiraRestClient by atlassian. I cannot create this client on every Jira interaction so I thought of caching this client. This client performs login in every ...
1
vote
1answer
34 views

How to use @Values fields in @Rule in JUnit?

How can I use @Value spring injected properties in a junit @Rule definition? Background: I want create a junit test with an embedded inmemory sftp server, using FakeSftpServerRule. Problem: a @Rule ...
0
votes
0answers
20 views

JUnit tests run separately but not all together using H2 database

I am running some JUnit tests that run perfectly separated one by one, but do not pass when they are all executed together. Here I show you some examples of the tests. I tried to close the connection ...
0
votes
0answers
42 views

@Autowired Spring Boot component is initialized in parent base class but happen to be null in child class [duplicate]

Why the myComponent ends up being null in child junit test class? How to fix it? Base JUnit test class: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class BaseTest { @...
0
votes
1answer
19 views

How to mock a mapper.query method when the return type is a PaginatedList of items JAVA

I am trying to test a method that uses DynamoDBMapper to query items from a dyamoDB table. My method works fine but the problem comes when I'm trying to test. I'm using Junt4 and Mockito. Basically,...
0
votes
1answer
50 views

Unit testing a public method that calls multiple private methods

I want to test a public method that calls multiple private methods. What I read from all the answers to previously asked questions are varying. Some say if one encounters such situation, then probably ...
-1
votes
0answers
13 views

How to generate class or JAR files from Robolectric test code in Android Studio?

I have some test codes based on Robolectric in Android Studio project. I would like to share these test codes to some programmers, but I want to hide the source code to them. I want they only execute ...
0
votes
0answers
16 views

How to run a Java application right after tests without Maven?

I have to do a test task and I am stuck at one point. It's said: 'The entry point of the whole application should lay through tests.' As I understand it: main(args[]) method should run right after the ...
-1
votes
0answers
29 views

how to fix error NullPointerException while using junit - selenium

/* I'm trying to execute one test case using junit, the problem arrives when i try to execute the set up steps from @beforeClass */ Error: java.lang.NullPointerException. Note: I imported the ...
2
votes
0answers
26 views

Best Practices for Unit Testing Builder Objects?

There is great debate about whether or not setters/getters should be unit tested. Example Should unit tests be written for getter and setters? I believe that builder objects fall within the same ...
1
vote
2answers
67 views

How to write JUnit test for a method that calls API?

I've to write test for a class that calls an API and then processes the response. The class has two public functions and a private function. The first public method fetches a list of IDs. The second ...
0
votes
0answers
17 views

Perform post in mock mvc doesn't pass param object

I want to test my controller if after login it'll set login field to a model. In the test, I create LoginForm object (simply object with username and password field) and I try to pass it in post ...
0
votes
0answers
12 views

How to add additional attributes (DisplayName and Tag) to JUnit 5 test result XML file?

I am running unit tests using the JUnit 5 framework using gradle. The test result XML file that it generates produces <testcase name="test_abc" classname="some.class.name" time="0.123"> ...
3
votes
1answer
26 views

InvalidUseOfMatchersException when using mockito to force a CloneNotSupportedException in a Copy() method being junit tested

I'm trying to access part of a copy method protected by a try catch using mockito while attempting to get 100% coverage in my junit tests. The class that contains the method I want to access ...
0
votes
1answer
31 views
+50

Missing refrences to test libraries in test class

I'm trying to run unit test on android module. This module has multiple product flavors with one dimension and two build types(debug + release). Also I have defined sourcesets for main, test and each ...