Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dinowernli/bazel-junit-autotest
A JUnit test runner which auto-detects tests. Intended for use with Bazel.
https://github.com/dinowernli/bazel-junit-autotest
Last synced: about 2 months ago
JSON representation
A JUnit test runner which auto-detects tests. Intended for use with Bazel.
- Host: GitHub
- URL: https://github.com/dinowernli/bazel-junit-autotest
- Owner: dinowernli
- License: apache-2.0
- Created: 2017-07-09T09:39:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-11T09:58:49.000Z (about 3 years ago)
- Last Synced: 2023-08-04T20:22:07.040Z (over 1 year ago)
- Language: Java
- Size: 22.5 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bazel-junit-autotest
A [JUnit](http://junit.org/junit4/) test runner which auto-detects tests. Intended for use with [Bazel](https://bazel.build/).
## Setup
In order to use autotest, first import the repo into your `WORKSPACE` file:
```python
git_repository(
name = "autotest",
remote = "https://github.com/dinowernli/bazel-junit-autotest.git",
tag = "v0.0.1",
)
```If you are not already importing the JUnit library jars, you can configure autotest by adding the following to your `WORKSPACE` file:
```python
load("@autotest//bzl:autotest.bzl", "autotest_junit_repo")
autotest_junit_repo(autotest_workspace="@autotest")
```
Alternatively, if you do already have the JUnit library jars available under a target called `//third_party/junit`, you can configure autotest by adding the following:```python
load("@autotest//bzl:autotest.bzl", "autotest_junit_repo")
autotest_junit_repo(junit_jar = "//third_party/junit", autotest_workspace="@autotest")
```## Writing tests
Inside your `BUILD` file, add:
```python
load("@autotest//bzl:autotest.bzl", "auto_java_test")
```Then, to declare a test, use `auto_java_test` as a drop-in replacement for the native `java_test`:
```python
auto_java_test(
name = "tests",
srcs = glob(['*.java']),
size = "small",
)
```The test runner will then scan the sources for types annotated with `@TestClass`, e.g.,
```java
import me.dinowernli.junit.TestClass;
import org.junit.Test;@TestClass
public class SomeTestClass {
@Test
public void testSomething() {
// ...
}
}
```## Scan depth
By default, only first entry of the classpath is scanned for annotated classes. If you want to scan more entries, you can pass a `test_arg`, e.g.,
```
bazel test //foo/bar:tests --test_arg=--scan_depth=7
```## Usage examples
For real-life examples, check out the [polyglot](https://github.com/grpc-ecosystem/polyglot/blob/master/src/test/java/me/dinowernli/grpc/polyglot/grpc/CompositeStreamObserverTest.java#L18) repo.