org.asarkar.grpc:grpc-test

JUnit5 Extension that can automatically release gRPC resources at the end of the test

License

License

Categories

Categories

gRPC Net Networking
GroupId

GroupId

org.asarkar.grpc
ArtifactId

ArtifactId

grpc-test
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

org.asarkar.grpc:grpc-test
JUnit5 Extension that can automatically release gRPC resources at the end of the test
Project URL

Project URL

https://github.com/asarkar/grpc-test
Source Code Management

Source Code Management

https://github.com/asarkar/grpc-test

Download grpc-test

How to add to project

<!-- https://jarcasting.com/artifacts/org.asarkar.grpc/grpc-test/ -->
<dependency>
    <groupId>org.asarkar.grpc</groupId>
    <artifactId>grpc-test</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/org.asarkar.grpc/grpc-test/
implementation 'org.asarkar.grpc:grpc-test:1.0.2'
// https://jarcasting.com/artifacts/org.asarkar.grpc/grpc-test/
implementation ("org.asarkar.grpc:grpc-test:1.0.2")
'org.asarkar.grpc:grpc-test:jar:1.0.2'
<dependency org="org.asarkar.grpc" name="grpc-test" rev="1.0.2">
  <artifact name="grpc-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.asarkar.grpc', module='grpc-test', version='1.0.2')
)
libraryDependencies += "org.asarkar.grpc" % "grpc-test" % "1.0.2"
[org.asarkar.grpc/grpc-test "1.0.2"]

Dependencies

runtime (3)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.72
org.junit.jupiter : junit-jupiter-api jar
io.grpc : grpc-api jar

Project Modules

There are no modules declared in this project.

grpc-test

Includes a JUnit 5 Extension that can automatically release gRPC resources at the end of the test. Like GrpcCleanupRule, but built for JUnit 5 and actively maintained.

Requires Java 8 or later. Verified working with the latest JUnit 5 version, which you can find in the gradle.properties.

Installation

You can find the latest version on Maven Central.

Usage

Declare a Resources in one of the three following ways, and register Server and/or ManagedChannel instances with it.

Get a Resources from:

  1. A test method parameter injection, or
  2. An instance field, or
  3. A static field.

The difference is in the lifecycle of the Resources object. For #1, a new instance is created for every test method. #2 is the same as #1 unless the test class declares @TestInstance(TestInstance.Lifecycle.PER_CLASS), in which case one instance is shared among all the tests. #3 is obviously one instance shared among all the tests.

Note that for #2 and #3, if the variable is already been assigned a value by the user, the extension will not reinitialize it.

@ExtendWith(GrpcCleanupExtension.class)
class ExampleTestCase {
    @Test
    void testSuccessful(Resources resources) {
        resources.register(server); // use default timeout
        resources.register(channel, Duration.ofSeconds(1)); // override default timeout
        resources.timeout(Duration.ofSeconds(3)); // change default timeout to 3 seconds
        resources.register(channel2) // channel2 timeout is 3 seconds; server and channel timeouts didn't change
    }
}

Contribute

This project is a volunteer effort. You are welcome to send pull requests, ask questions, or create issues. If you like it, you can help by spreading the word and "Starring" the GitHub repo!

License

Copyright 2021 Abhijit Sarkar - Released under Apache License v2.0.

Versions

Version
1.0.2
1.0.0