junit
Replacing PowerMock’s @PrepareForTest programmatically?
What you try to achieve will not work. The problem is that powermock must rewrite the client class’s code to intercept the static invocation and it can’t do this after the class is loaded. Thus it can only prepare a class for test before it is loaded. Let’s assume you want to mock the System.currentTimeMillis … Read more
Mockito; verify method was called with list, ignore order of elements in list
As noted in another answer, if you don’t care about the order, you might do best to change the interface so it doesn’t care about the order. If order matters in the code but not in a specific test, you can use the ArgumentCaptor as you did. It clutters the code a bit. If this … Read more
IntelliJ scroll console to end after test execution
For me (in webstorm 2020) the solution was to click the cog wheel, then select Scroll to Stack Trace. I’m sure in all the Jetbrains products this is the solution.
IntelliJ IDEA debugger skips breakpoints when debugging Maven tests
Just disable the forked mode – something like this in your pom file (under project/build/plugins section): <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.14</version> <configuration> <forkMode>never</forkMode> </configuration> </plugin>
Mock static method in JUnit 5 using Mockito
You need to use mockito-inline version 3.4.0 or higher and remove mockito-core from your dependencies (mockito-inline depends on mockito-core so it will be retrieved automatically). That way, you will be using mockito static mocking correctly, but it wouldn’t solve the exception that you posted. To fix it, you need to remove all dependencies of powermock … Read more
junit assert in thread throws exception
The JUnit framework captures only assertion errors in the main thread running the test. It is not aware of exceptions from within new spawn threads. In order to do it right, you should communicate the thread’s termination state to the main thread. You should synchronize the threads correctly, and use some kind of shared variable … Read more
Java JUnit 5 annotations differences
org.junit.Test is not in JUnit5, that class is being provided by your dependency on JUnit Vintage. JUnit Vintage includes the JUnit Vintage test engine and classes such as org.junit.Test, this allows you to run JUnit4 tests alongside JUnit5 tests. It is a back compatability measure. If you want to use only JUnit5 constructs (and leave … Read more
assert equals int long float
One workaround with some overhead would be to wrap the values in BigDecimal objects, as BigDecimal constructor overloads take long, int and double primitives. Since new BigDecimal(1l).equals(new BigDecimal(1.0)) holds true, Assert.assertEquals(new BigDecimal(1.0), new BigDecimal(1l)); should work for you. Edit As Hulk states below, the scale of the BigDecimal objects is used in the equals comparison, … Read more