Linked Questions
10 questions linked to/from How does Junit @Rule work?
185 votes
8 answers
443k views
Initialising mock objects - Mockito
There are many ways to initialize a mock object using MockIto. What is best way among these ? 1. public class SampleBaseTestCase { @Before public void initMocks() { MockitoAnnotations....
1 vote
1 answer
7k views
JUnit running test methods conditionally
import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; public class SwiftTest { SwiftUtil swiftUtil = new SwiftUtil(); boolean result; @Test public ...
1 vote
1 answer
2k views
How to share an ExternalResource between two test classes?
I am struggling a bit to understand the benefit of using ExternalResource. The documentation and other posts (How Junit @Rule works?) have all alluded to being able to share code between tests within ...
1 vote
3 answers
808 views
How can I declare "mixins" for JUnit tests?
I have a lot of JUnit tests in my projects. Some of them have some side-effects that can influence the execution of other tests. For example, they open database connections and forget to close them, ...
0 votes
2 answers
1k views
Any Ideas why Aspect for Custom Annotation is not called?
I try to use the following Annotation to Authenticate in Testing of my Spring Boot 2 Application. @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Documented public @interface ...
2 votes
1 answer
396 views
Continue test execution after network failure
This is a interview question which took my wicket. We have a selenium test class with 5,6 selenium tests. Test 3 is in execution, and network failure happened. Now once network resumes back, how to ...
1 vote
1 answer
618 views
JUnit Contract Testing with Suites
I have an interface that defines a contract (i.e. a Repository), with few implementations. Each method in the interface represents a feature, and I would like to test each feature in its suite test ...
1 vote
1 answer
214 views
Creating a configurable JUnit library to test same features across several microservices
A set of tests should be run on every microservice. Current solution is to have an abstract class and extend in every service, providing the necessary properties in abstract getters. public abstract ...
0 votes
0 answers
168 views
How do I use @RunWith with both JUnit4ClassRunner and JUnitParams? [duplicate]
I am writing an integration test that is a parameterized test, and I need to include @RunWith(SpringJUnit4ClassRunner.class) and @RunWith(JUnitParamsRunner.class). The problem is that I can only ...
0 votes
1 answer
162 views
Running jetty web server before selenide tests
I have multi module maven project. One parent and two submodules. In first module I have integration tests, specifically selenide tests, which are testing web application. Web application is in the ...