ProtoTap is a Gradle plugin that allows tapping output of Protobuf compiler used in the project to
which the plugin is applied, and placing them as test
resources.
This way authors of code generators can focus on writing tests rather than on "plumbing" with
Protobuf Plugin for Gradle or creating a custom diagnostic plugin for
Protobuf Compiler (protoc
).
ProtoTap interacts with Protobuf Plugin for Gradle for copying generated code and
related files to test
resources of the project. Files are stored under the directory matching
the following pattern:
$projectDir/build/resources/test/prototap/
When tuning code generation, the plugin attempts to find testFixtures
source set
in the project first. If not found, the plugin attempts to find the test
source set.
Using other source sets requires explicit setting, as described in the section below.
The code generated by protoc
will appear in corresponding subdirectories of the prototap
.
The name of the subdirectory matches the name of the corresponding protoc
built-in or plugin.
For example, for java
built-in it would be:
my-project
build
resources
test
prototap
java <-- The output of `java` built-in of `protoc`.
HelloWorld.java
After this, the code of your tests will be able to access the generated code as usual program resources.
CodeGeneratorRequest
is passed by protoc
to its plugins when .proto
files
are processed. ProtoTap stores the binary version of the request in the file
named CodeGeneratorRequest.binbp
next to the directories with the generated code:
my-project
build
resources
test
prototap
java
CodeGeneratorRequest.binbp <—— The request file.
Adding to your project via Kotlin DSL looks like this:
plugins {
id("io.spine.prototap") version "$version"
}
The above snippet assumes that the plugin with the ID "com.google.protobuf"
is already
added and configured in your project.
Tip
For the latest ProtoTap version please see version.gradle.kts
.
The plugin was developed and tested under Gradle 7.6.4.
You can tune ProtoTap by using the following DSL:
prototap {
sourceSet.set(functionalTest)
generateDescriptorSet.set(true)
}
The sourceSet
property is for specifying a source set with the proto files of interest, other
than testFixtures
or test
.
The generateDescriptorSet
property makes the Protobuf Compiler produce a descriptor set file,
which ProtoTap places next to CodeGeneratorRequest
:
my-project
build
resources
test
prototap
java
CodeGeneratorRequest.binbp
FileDescriptorSet.binpb <—— The descriptor set file.
By default descriptor set files are not generated.