Questions tagged [junit4]

Version 4 of the popular Junit Java Unit testing framework

Version 4 of the popular JUnit Java Unit testing framework.

New features are the introducing of annotations to use the framework.

Use this tag only for question related to features provided by version 4. Use for general questions.

4127 questions
1
vote
1 answer

How to perform unit test on a server socket?

I am a beginner in Java. I have built a client-server group chat application watching tutorials. I read a lot about unit tests and can implement in simple maths problems but i don't know how does it work out for complex codes. So I want to see a…
1
vote
0 answers

org.junit.runners does not exist in June 5

I am migrating from junit 4 to 5 and I see that the following packages do not exist. org.junit.rules.TestRule, org.junit.runner.Description; org.junit.runners.model.Statement; import org.h2.jdbcx.JdbcConnectionPool; import…
1
vote
0 answers

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/test/platform/io/FileTestStorage;

Firstly I did not have androidTest Package in my App, So I created using Run-> Record Espresso Test, So it Created an androidTest package. But Getting this Exception in Logcat while running an Instrumented test. I have Gone through lot of solutions…
Roop Kishore
  • 199
  • 1
  • 11
1
vote
1 answer

How can I unit test a MVC Model 2 application using junit and jmock?

How can I unit test a MVC Model 2 application using junit and jmock? I have a MVC Model 2 application fully functional but has zero unit tests. I am implementing unit tests around the application. I would like to unit test my controller servlet…
user477402
  • 65
  • 2
  • 6
1
vote
3 answers

Re-using login functionality in Selenium page object model tests

I am exploring the use of Selenium 2 on a web application which requires authentication before a user can use any of the application. I am planning on either JUnit 4 or TestNG (Still investigating which one to use with Grid 2). I may plan to use…
Ilyas Patel
  • 400
  • 2
  • 11
  • 27
1
vote
0 answers

System.getenv("SOME_ENV_VAR") is returning null value in intelliJ IDEA ultimate edition

Java version: java 11.0.14 2022-01-18 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.14+8-LTS-263) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.14+8-LTS-263 IntelliJ IDEA ultimate version: 2021.3.2 Default shell set to bash when running…
1
vote
1 answer

How to test this code in junit 4 and java 8?

I'm trying to testing this code in junit 4 and java 8 (I can't improve the version). The thing is, I can't use in this version @MockBean or @Autowired for test coding, so, ¿what's the better option if I can't improve the version? Code: public class…
1
vote
2 answers

how can I initialise global variable of class in Junit 5?

I am upgrading Junit 4 to Junit 5 and want to convert parameterized test from Junit4 to Junit5, but facing below issue. @RunWith(Parameterized.class) public class PrimeNumberCheckerTest { @Parameter(0) private Integer inputNumber; …
Sagar Vaghela
  • 1,165
  • 5
  • 20
  • 38
1
vote
1 answer

Junit5: Equivalent of @Rule and Expect

I have some code which I have written in old version of jUnit. Now I am trying to migrate. How to write this in Junit5? @Test public void testSignatureFailureRuntimeException() throws Exception { …
Piku
  • 15
  • 4
1
vote
1 answer

MockEJB fails when upgrade to jdk1.6

We are in the process of upgrading our J2EE application from jdk1.4 to jdk1.6 along with moving to a different application server. Yes, lots of moving parts. However, I had written a number of junit tests using Mockrunner and MockEjb where I call…
Bob
  • 81
  • 7
1
vote
2 answers

Finishing details on a JUnit 4 dynamic suite

Hi – I wanted to automatically sweep JUnit tests into suites as part of my continuous builds, so I derived a runner from JUnit's Suite which finds all test classes in a package. The runner works just fine, but the results display is less than…
carym
1
vote
1 answer

Junit tests are failing after I upgrade the spring boot dependencies

I have the following code that is running fine when I had spring boot dependencies 2.3.3. class Details { String pin; State state; } class DetailsDto { String pin; StateDto stateDto; } class State { } class StateDto { } @Named class…
Naren
  • 139
  • 1
  • 17
1
vote
0 answers

Mocking a URL connection using PowerMockito

I am trying to test my code which parses a JSON response from a URL. This is the code I'm trying to test: public String getJsonResponseFromUrl(String url) { JSONObject jsonObject = null; try { URL apiUrl = new…
Shaun Aran
  • 123
  • 4
  • 17
1
vote
1 answer

How to write junit cases for @Bean for configuration classes

I have the below method in the @Configuration class and I need to write JUnit for this. Can anyone please guide me to achieve the JUnit test case? @Bean @Profile({"!test & !local"}) @Primary public DiscoveryClient.DiscoveryClientOptionalArgs…
Sdcoder
  • 33
  • 2
  • 4
1
vote
1 answer

Unable to Run Container Using testcontainers

I'm trying to implement a JUnit (v4.13.2) test using testcontainers (v1.16.2) to better test our DAO/JPA classes. I'm using the centos/postgresql-96-centos7 official docker image and I can run it on the cmd line just fine using: docker run -d --name…
Sean Smitz
  • 31
  • 1
  • 6