1.6 KiB
1.6 KiB
Standard Tests Development Guide
Standard test cases are found in betterproto/tests/inputs, where each subdirectory represents a testcase, that is verified in isolation.
inputs/
bool/
double/
int32/
...
Test case directory structure
Each testcase has a <name>.proto
file with a message called Test
, a matching .json
file and optionally a custom test file called test_*.py
.
bool/
bool.proto
bool.json
test_bool.py # optional
proto
<name>.proto
— The protobuf message to test
syntax = "proto3";
message Test {
bool value = 1;
}
You can add multiple .proto
files to the test case, as long as one file matches the directory name.
json
<name>.json
— Test-data to validate the message with
{
"value": true
}
pytest
test_<name>.py
— Custom test to validate specific aspects of the generated class
from betterproto.tests.output_betterproto.bool.bool import Test
def test_value():
message = Test()
assert not message.value, "Boolean is False by default"
Standard tests
The following tests are automatically executed for all cases:
- Can the generated python code imported?
- Can the generated message class be instantiated?
- Is the generated code compatible with the Google's
grpc_tools.protoc
implementation?
Running the tests
pipenv run generate
This generatesbetterproto/tests/output_betterproto
— the plugin generated python classesbetterproto/tests/output_reference
— reference implementation classes
pipenv run test