org.mockito.junit.MockitoRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockito-core Show documentation
Show all versions of mockito-core Show documentation
Mock objects library for java
/*
* Copyright (c) 2016 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.junit;
import org.junit.rules.MethodRule;
/**
* Since 2.1.0, JUnit rule emits stubbing warnings and hints to System output
* (see also {@link org.mockito.quality.MockitoHint}).
* The JUnit rule can be used instead of {@link org.mockito.runners.MockitoJUnitRunner}.
* It requires JUnit at least 4.7.
*
* This rule adds following behavior:
*
* -
* Since 2.1.0, stubbing warnings and hints are printed to System output.
* Hints contain clickable links that take you right to the line of code that contains a possible problem.
* Please give us feedback about the stubbing warnings of JUnit rules in the issue tracker
* (issue 384).
* It's a new feature of Mockito 2.1.0. It aims to help debugging tests.
* If you wish the previous behavior, see {@link MockitoRule#silent()}.
* However, we would really like to know why do you wish to silence the warnings!
* See also {@link org.mockito.quality.MockitoHint}.
*
-
* Initializes mocks annotated with {@link org.mockito.Mock},
* so that explicit usage of {@link org.mockito.MockitoAnnotations#initMocks(Object)} is not necessary.
* Mocks are initialized before each test method.
*
-
* Validates framework usage after each test method. See javadoc for {@link org.mockito.Mockito#validateMockitoUsage()}.
*
*
* Example use:
*
* public class ExampleTest {
*
* @Rule
* public MockitoRule rule = MockitoJUnit.rule();
*
* @Mock
* private List list;
*
* @Test
* public void shouldDoSomething() {
* list.add(100);
* }
* }
*
*
* @since 1.10.17
*/
public interface MockitoRule extends MethodRule {
/**
* Rule will not report stubbing warnings during test execution.
* By default, stubbing warnings are printed to Standard output to help debugging.
*
* Please give us feedback about the stubbing warnings of JUnit rules.
* It's a new feature of Mockito 2.1.0. It aims to help debugging tests.
* We want to make sure the feature is useful.
* We would really like to know why do you wish to silence the warnings!
* See also {@link org.mockito.quality.MockitoHint}.
*
*
* Example:
*
* public class ExampleTest {
*
* @Rule
* public MockitoRule rule = MockitoJUnit.rule().silent();
*
* }
*
*
* @since 2.1.0
*/
MockitoRule silent();
}