Reuse spring application context across junit test classes

We've a bunch of JUnit test cases (Integration tests) and they are logically grouped into different test classes. We are able to load Spring application context once per test class and re-use it...

What's the best way to set up a per-test or per-class timeout when using <junit> in perBatch forkmode?

I want to fail the build if anyone writes a test that takes longer than 1 second to run, but if I run in perTest mode it takes much, much longer. I could probably write a custom task that parses...

maven error: package org.junit does not exist

I'm trying to create the javadoc with maven and it fails. It also fails when doing the verify. mvn verify I get the following error: (...) [INFO]...

How to handle SSL errors for chrome and internet explorer in selenium Webdriver testing?

How we can handle SSL certificate errors for chrome and internet explorer with selenium web driver. When I am working with Firefox it is working fine. Could you please provide me the solution to...

Can I simulate a specific filesystem while unit testing?

I have been googling a little and did not find an answer which suited my specific case. I am working on a project file manager classes, and discovered that it was developped to behave differently...

How to test that no exception is thrown?

I know that one way to do it would be: @Test public void foo() { try { // execute code that you expect not to throw Exceptions. } catch(Exception e) { fail("Should not have...

java.lang.Exception: No runnable methods exception in running JUnits

I am trying to run the JUnit on my Linux command prompt /opt/junit/ contains the necessary JARS(hamcrest-core-1.3.jar and junit.jar) and class files and I am using the following command to run the...

Intermittent NoClassDefFoundError when running a maven/surefire build in jenkins

We are building a large multi module Maven project on Jenkins, including running a large number of unit test. Once every few builds the build fails on NoClassDefFoundError on RunListener - which...

How to test the method that reads the data from the excel file in java?

The above picture shows the excel file containing the Facebook data. The class FacebookDataExtraction reads the data from the Excel file and stores the data as list of row objects as shown in the...

Mockito: Mock private field initialization

How I can mock a field variable which is being initialized inline? class Test { private Person person = new Person(); ... public void testMethod() { person.someMethod(); ...

JMeter JunitSampler unable to find constructer with string parameter

I am working on performance testing a command line tool. I already have an integration test written using Junit that tests the entirety of the command line tool and I'd like to reuse it for...

Why does Buildozer show `# Aidl not found, please install it.` even after I installed it?

I have installed build-essential, libstdc++6,and, aidl itself: sudo apt-get install aidl Reading package lists... Done Building dependency tree Reading state information... Done The...

How to find the whether the current using window is maximize or minimize in selenium 2 WebDriver?

Is there any way to find the currently used browser window is whether maximized or minimized in Selenium as I am using JUnit for make test script of automation. Thanks, Mohan Raj

How to define @Rule and @ClassRule with junit5

I want to migrate junit4 to junit5 , And I use @Rule annotations for junit4. Like this: public class A { @ClassRule public static final SpringClassRule SPRING_CLASS_RULE = new...

JUnit AssertEquals fails

I have a code which for the following import static org.junit.Assert.assertEquals; System.out.println("obj1 name = " + obj1.getName()); System.out.println("obj1 value = " + (obj1.getvalue() ==...

Can't assert an exception with AssertJ

I have the following negative test code (needs to fail and throw an exception): @Test public void testInventoryControllerGetNonExistingRegion() { final String name = "ME_2"; ...

How to test different implementations for an interface in Junit5 without duplicating the code

May I ask how to write a junit 5 test for an interface with different implementations? For example, I have a interface Solution, with different implementations like SolutionI, SolutionII, can I...

Equivalent for @RunWith(JUnitPlatform.class) for JUnit5

In my project I'm doing some cleanup and decided to move everything to JUnit5. Till this time, I was using @RunWith(JUnitPlatform.class) Now I want to migrate it to @ExtendWith. Is there any...

JUnit test class order

I have a java app with maven. Junit for tests, with failsafe and surefire plugins. I have more than 2000 integration tests. To speed up the test running, I use failsafe jvmfork to run my tests...

How to get the result from select query using Spring boot

I have a native query in Spring-boot from which I want to get result using rest call, but I'm doing something wrong which is not giving me result. Please see my code below When I call the...

@InjectMocks inject @MockBean by Constructor and setter not working properly

I have try so many time by unsing @RunWith(SpringJUnit4ClassRunner.class) I have tried to create a test case foe a class with getter and Constructor injection. When i user @MockBean for setter...

Why am I getting a StackOverflowError in my JUNIT Test?

Info For our school assignment we had to make a 'maze' and recursively depth first search through it. While doing that, we have to store the solution to the maze. I decided to use an adjacency...

No tests found for given includes Error with powermock

I was trying to use powermock to mock my static method. Here's the test class: @RunWith(PowerMockRunner.class) public class ThemeServiceImplTest { @Test @PrepareForTest(GitUtils.class) ...

Cucumber No features found with JUnit5

I am trying to setup Cucumber in my project. I am following the same configuration from my previous projects but I still have issues with running the tests. Now I am starting to suspect that the...

Type mismatch junit5 @ExtendWith

so this is probably a really dumb question but I just started to migrate a project from junit 4 to 5 and saw that @RunWith() does not longer exists. It is replaced by @ExtendWith. So I tried to do...

Jetpack Compose Preview not showing

I seem to be having trouble with Preview in compose, the layout panel doesn't appear when I annotate a compose method with @preview. I assume I'm missing a dependency, but I've copied and pasted...

Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8

I download the newest Android Studio, I want to run the Android Jetpack Compose Project, But when I run , I got the error: > Failed to apply plugin 'com.android.internal.application'. >...

Why do my tests pass when run together, but fail individually?

Not to be confused with a previously asked question "Why do my tests fail when run together, but pass individually?" I have a task where I need to modify Junit test classes to handle multiple...

org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during psi2ir in Jetpack compose

I am getting this error during compilation or code generation, I have set the jetpack compose dependencies and working on it, I have made some compose components and previews are visible but...

Unable to find method void org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions.setUseIR(boolean)

I'm unable to run any tests or run the app or debugger because of this error: `Unable to find method void org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions.setUseIR(boolean)` I've tried all of...