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
18 views

How to test Web Service calls through Junit

I would like to test my web service using Junit. Once we missed the public modifier and it failed. So, to avoid such issue in the earlier stage we would like to write Junit test cases to test the web ...
0
votes
0answers
12 views

How to run specific test cases with Jenkins?

I created a Jenkins job to run some junit test in a maven project. Following is the configuration: In the properties I set test=TS_1609 to run one test and I want to know how can I specify several ...
0
votes
0answers
16 views

Spring-Boot-Tests not running in eclipse

I have a project with a load of spring-boot-tests that run fine when I do a mvn build, but always fail almost immediately when i run them from eclipse. The tests from a different project, that are ...
0
votes
1answer
17 views

Assert.fail equivalent using hamcrest

I use JUnit for Assert.fail but I do not know what is the Hamcrest equivalent. Does anyone know?
0
votes
0answers
7 views

Websocket client unit test on spring boot

I have spring boot project with websocket client code and I would like to write junit test for the same. But I am not sure how to mock websocket behavior in the unit test. How to write junit test for ...
-2
votes
1answer
29 views

How to write JUnit test cases for generic array

How can I write a test case for the below generic method? public <T> T getValueAtIndex(int i) { return (T) values[i]; }
0
votes
1answer
16 views

Mocking of MongoClient first returns null

I am trying to mock the findIterable.first(), but it returns null. I am mocking mongodb connection and a find query. Query i am trying to test FindIterable<Document> a=applicationproperties....
0
votes
0answers
11 views

Run Android Unit Test with Command Line Feature Module NoClassDefFoundError

In my project, I use dynamic feature module, and I want to run my unit test in feature module via command line (for my CI purpose), I run with this command ./gradlew :feature_product:test But it ...
0
votes
1answer
25 views

How to mock a value to test a conditional in another method with JUnit/Mockito?

I am new to JUnit and Mockito, and am struggling trying to mock a value coming back from a boolean method to hit inside a conditional. I have tried the answer from this post, but doesn't seem to ...
0
votes
0answers
11 views

Android unit tests getting failed due to network issue

Unexpected exception thrown. org.gradle.internal.remote.internal.MessageIOException: Could not write '/127.0.0.1:63602'. at org.gradle.internal.remote.internal.inet.SocketConnection.flush(...
0
votes
1answer
20 views

Testing a java jersey application

I have a java/jersey api that is called from the front end. I need to write tests for the java code. How the code is written is: 1. The api call executes the resource method, this calls a separate ...
0
votes
0answers
12 views

How can I run cucumber tests in ant JUnit task?

I am supposed to run my cucumber tests (defined in the feature files) in the java project. There should be either a java or JUnit task defined in the pom.xml within maven-antrun-plugin to run the ...
0
votes
1answer
23 views

How to use an Or with a JUnit assume

In a jUnit test case, I'm trying to use an Assume that will check if a condition is true OR if another one is true. However, jUnit will effectively stop the test as soon as one condition is true. In ...
0
votes
0answers
5 views

Converting junit xml result files to simple output

I would like to convert a folder full of JUnit XML files to a simplified console output. Is this possible with some tool out-of-the-box? If so, how? Any kind of command-line tool would be fine.
0
votes
1answer
40 views

Skipping integration tests in spring boot on VPN DNS availability

I have a moderately heavy springboot service, it takes 10-15 seconds to boot on a happy flow, and (1-2) minutes to fail on a retry/failover flow. This is ok for my business flows, and is how I expect ...
0
votes
0answers
15 views

org.mockito.exceptions.misusing.UnfinishedVerificationException

I have a class and I would like to test the retryServiceConnector method. The code is provided, @Configuration @EnableKafkaProducer @ComponentScan( "com.ratepay.ella.service.io" ) public class ...
0
votes
0answers
4 views

Stanfort CoreNLP NER does not run in junit tests

I got Stanford CoreNLP running a named entity recognition in my java application which works fine. Now I port my exact code into a junit tests and it does not work (no exception, no output). It is ...
0
votes
0answers
11 views

Intermittent NoClassDefFoundError for Kotlin class ProtoBuf$EnumEntryOrBuilder

In a run of our Kotlin JUnit tests on CI, we had a number of failures that errored with: java.lang.NoClassDefFoundError: kotlin/reflect/jvm/internal/impl/metadata/ProtoBuf$EnumEntryOrBuilder With ...
0
votes
0answers
12 views

Unable to set SecurityManager in a SpringJUnit4ClassRunner test case

I wanted to test System.exit in a Spring test case and would like to use SecurityManager to catch the exit and throw an exception. The test case is defined as follows: @RunWith(...
1
vote
0answers
19 views

UnsatisfiedDependencyException: Requested bean is currently in creation unresolvable circular reference

I have a source class that apparently break the integration test. The code is provided below. @Configuration @Import( EmailageConfiguration.class ) public class EmailageServiceConfiguration { ...
1
vote
2answers
57 views

Mockito: Zero interactions with this mock

I have a class that I would like to test. @Configuration @Import(EmailageConfiguration.class) public class EmailageServiceConfiguration { private static final String ...
-1
votes
1answer
49 views

Compare all properties in two objects of different classes in unit test

I have some objects (of different class) say PersonType1 and PersonType2 and trying to compare the fields are equal in the test case. The scenario is like: jsonA -> PersonTypeA; jsonB -> ...
0
votes
1answer
33 views

Why JUnit not calling explicit no arg ctor in same package as test

Simple JUnit test, in same package as code under test, but in different source (src) folder. NullPointerException thrown since it appears that my JUnit code is not invoking my no-arg ctor in source ...
0
votes
1answer
21 views

java.lang.NoSuchMethodError on using org.json.JSONTokener for schema validation failing when running junit test case

I have added the code new JSONObject(new JSONTokener(EsimActivationProcessor.class.getResourceAsStream)) to validate the input json request against the json schema. The validation on server and normal ...
0
votes
0answers
17 views

how do I know which runner file is triggered

I have multiple runner.java files for cucumber test for different purpose, such as some is for smoke test, some is for regression test. How do I set which runner file is called when I run the ...
0
votes
1answer
21 views

How can I convince eclipse/JUnit4 to find all my tests, in a gradle/eclipse project?

Background JUnit 4 test runner, within Eclipse 4.11. I have an eclipse project that was imported from a build.gradle file. This project has several different source paths, each with their own test ...
-1
votes
1answer
50 views

Write a Test case with junit

What ist the correct way to write a test case with Junit for this SetScene Methode? public static void SetScene(int index){ root.getChildren().remove(liste.get(indexcurrent)); root.getChildren()....
0
votes
1answer
19 views

What's the difference between @RunWith(MockitoJUnitRunner.class) and @RunWith(SpringJUnit4ClassRunner.class)? When to use it appropriately?

What's the difference between @RunWith(MockitoJUnitRunner.class) and @RunWith(SpringJUnit4ClassRunner.class)? When to use it appropriately?
1
vote
1answer
32 views

Spring Boot - Mock a POST REST request to an external API

I have a Spring-Boot 1.5.21 application that serves as a REST gateway between an Angular UI and an external API that provides the data (long story - acts as auth between UI and datasource). A request ...
-3
votes
1answer
25 views

Spring Batch Unit Testing( Junit )

Are there any references available for spring batch Junit testing?, After so much search i am unable to find any good example references .
0
votes
0answers
12 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
47 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
36 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
25 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
23 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
33 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
56 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 ...
0
votes
1answer
39 views

Cannot hit break point in java app when running the whole junit integration test class

Newbie question: java 8 app, using JUnit to test. Using maven, IntelliJ. Say this integration test is tests.api.users.TestCreateUser, inside it has some test cases say t1, t2, t3, ... I set a break ...
-1
votes
1answer
56 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
25 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
19 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
16 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
17 views

EmbeddedKafka vs KafkaTestUtils [closed]

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
16 views

Unable to mock ApplicationContext

I am unable to mock ApplicationContext. private CommonAppContextProvider commonAppContextProvider; ApplicationContext applicationContext = mock(ApplicationContext.class); when(...
0
votes
0answers
21 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
1answer
77 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
38 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 ...