Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mockito/mockito-testng
Mockito TestNG support
https://github.com/mockito/mockito-testng
mocking mockito testng
Last synced: 2 months ago
JSON representation
Mockito TestNG support
- Host: GitHub
- URL: https://github.com/mockito/mockito-testng
- Owner: mockito
- License: mit
- Created: 2018-08-01T02:42:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-11-30T05:41:29.000Z (about 1 year ago)
- Last Synced: 2024-05-09T09:02:40.428Z (8 months ago)
- Topics: mocking, mockito, testng
- Language: Java
- Homepage:
- Size: 253 KB
- Stars: 13
- Watchers: 3
- Forks: 10
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mockito for TestNG
Mockito utility classes for easy integration with TestNG
[![CI](https://github.com/mockito/mockito-testng/workflows/CI/badge.svg)](https://github.com/mockito/mockito-testng/actions?query=workflow%3ACI)
[![Maven Central](https://img.shields.io/maven-central/v/org.mockito/mockito-testng.svg)](https://search.maven.org/artifact/org.mockito/mockito-testng/)
## Installation
### Gradle
```Gradle
dependencies {
testCompile "org.mockito:mockito-testng:VERSION"
}
```### Maven
```xmlorg.mockito
mockito-testng
VERSION
test```
For latest version, see the [releases](https://github.com/mockito/mockito-testng/releases).
## Usage
Simply add `@Listeners` annotation on your test class
```java
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.testng.MockitoTestNGListener;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;import java.util.Map;
@Listeners(MockitoTestNGListener.class)
public class MyTest {@Mock
Map map;@InjectMocks
SomeType someType;@Test
void test() {
// ...
}
}
````MockitoTestNGListener` will do job for you and initialize all fields annotated with mockito annotations.
By default `MockitoSession` is started with `STRICT_STUBS`.
You can change this behavior by adding `@MockitoSettings` to your test class.```java
import org.mockito.quality.Strictness;
import org.mockito.testng.MockitoTestNGListener;
import org.mockito.testng.MockitoSettings;
import org.testng.annotations.Listeners;@Listeners(MockitoTestNGListener.class)
@MockitoSettings(strictness = Strictness.WARN)
public class MyTest {
// ...
}
```## Notices
- `MockitoSession` is started before each `test method` or before method annotated with `@BeforeMethod`,
another annotations `@BeforeXXX` aren't supported #40
## Developing- open in IDEA to develop or run ```./gradlew idea``` and then open in IDEA
- ```./gradlew build``` - tests code and assembles artifacts
- ```./gradlew publishToMavenLocal``` - publishes to local Maven repo, useful for local testing## Releasing
Every merged pull request is published to Maven Central.
Actually, any change on master that happily builds on CI is published.
The release automation uses Shipkit framework (http://shipkit.org).## History
The original TestNGListener was a part of the core Mockito repository. However, the jar was never released. Core Mockito team does not work with TestNG so it was hard for us to maintain TestNG integration. In Summer 2018 we moved the TestNG integration to a separate repository under "Mockito" organization.
## Help
We are looking for maintainers of TestNG integration! Let us know if you want to join. Mockito core team has limited capacity and focuses on the core library.