gRPC Testify đ ī¸ â
Declarative testing for gRPC services using simple .gctf
configuration files.
Features â
- đ PLAINTEXT communication only
- đ¯ Request/response validation
- đĻ Error code assertions
- đ Human-readable reports
- đ Recursive directory processing
Installation â
Recommended Installation (macOS/Linux) â
bash
brew tap gripmock/tap
brew install grpctestify
In this case, grpctestify
will automatically install grpcurl
and jq
as dependencies.
Manual Installation â
Install Dependencies â
bash
# macOS
brew install grpcurl jq
# Ubuntu/Debian
sudo apt install -y grpcurl jq
# Verify installation
grpcurl --version
jq --version
Download the Script â
Use curl
or wget
to download the grpctestify.sh
script from the latest release:
bash
# Using curl
curl -LO https://github.com/gripmock/grpctestify/releases/latest/download/grpctestify.sh
# Using wget
wget https://github.com/gripmock/grpctestify/releases/latest/download/grpctestify.sh
Make the Script Executable â
After downloading, make the script executable:
bash
chmod +x grpctestify.sh
Move the Script to a Directory in Your PATH (Optional) â
For easier access, move the script to a directory in your PATH
:
bash
sudo mv grpctestify.sh /usr/local/bin/grpctestify
Verify Installation â
Check that the script is working correctly:
bash
grpctestify --version
Test File Format â
php
--- ADDRESS ---
localhost:50051
--- ENDPOINT ---
package.service/Method
--- REQUEST ---
{
"key": "value"
}
--- RESPONSE ---
{
"result": "OK"
}
--- ERROR ---
Key Concepts â
1. Address Handling â
- Default address:
localhost:4770
- Override via test file:yaml
--- ADDRESS --- localhost:50051
- Override via environment (bash):bash
export DEFAULT_ADDRESS=localhost:50051
2. Response/Expectation Rules â
- Exactly one of
RESPONSE
orERROR
must be present RESPONSE
validates successful responses (status code 0)ERROR
validates gRPC error codes/messages (non-zero status)
3. Communication Protocol â
- Only PLAINTEXT supported (no TLS)
- Uses
grpcurl -plaintext
for all requests
Command-Line Options â
bash
$ ./grpctestify.sh --help
âļ gRPC Testify v0.0.3 - gRPC Server Testing Tool
INF Usage: ./grpctestify.sh [options] <test_file_or_directory>
INF Options:
--no-color Disable colored output
--verbose Show debug output (request/response details)
--version Print version
-h, --help Show help
Practical Examples â
1. Calculator Service Tests â
math_add.gctf
yaml
--- ENDPOINT ---
calculator.Math/Add
--- REQUEST ---
{
"a": 5,
"b": 3
}
--- RESPONSE ---
{
"result": 8
}
math_divide_by_zero.gctf
yaml
--- ENDPOINT ---
calculator.Math/Divide
--- REQUEST ---
{
"a": 10,
"b": 0
}
--- ERROR ---
{
"code": 3, # INVALID_ARGUMENT (see status codes reference)
"message": "division by zero"
}
2. User Management Tests â
user_create.gctf
yaml
--- ADDRESS ---
localhost:50052
--- ENDPOINT ---
user.Manager/Create
--- REQUEST ---
{
"name": "Alice",
"email": "alice@example.com"
}
--- RESPONSE ---
{
"id": 123,
"status": "created"
}
user_invalid_email.gctf
yaml
--- ENDPOINT ---
user.Manager/Create
--- REQUEST ---
{
"name": "Bob",
"email": "invalid-email"
}
--- ERROR ---
{
"code": 16, # UNAUTHENTICATED (example code)
"message": "invalid email format"
}
CI/CD Integration â
GitHub Actions Example â
yaml
name: gRPC Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y grpcurl jq
- name: Run tests
run: |
curl -sSL https://raw.githubusercontent.com/gripmock/grpctestify/master/grpctestify.sh -o grpctestify.sh
chmod +x grpctestify.sh
./grpctestify.sh tests/
Best Practices â
- Test Organization:
tests/
âââ math/
â âââ add_valid.gctf
â âââ divide_by_zero.gctf
âââ user/
âââ create_success.gctf
âââ invalid_email.gctf
- Validation Rules:
- Use
jq
-compatible JSON in all sections - Match error codes from gRPC status codes
- Keep test files focused (one operation per test)
Limitations â
- No TLS support (PLAINTEXT only)
- Requires valid JSON formatting
- Error messages must exactly match server responses
Advanced Usage â
Verbose Output Example â
bash
$ ./grpctestify.sh --verbose math_add.gctf
âšī¸ Starting test suite
đ Processing file: math_add.gctf
INF Configuration:
ADDRESS: localhost:4770
ENDPOINT: calculator.Math/Add
REQUEST: {"a":5,"b":3}
RESPONSE: {"result":8}
đ Executing gRPC request to localhost:4770...
â
TEST PASSED: math_add
Directory Execution â
bash
$ ./grpctestify.sh tests/
...
â
TEST PASSED: add
...
â
TEST PASSED: divide_by_zero
...
â
TEST PASSED: create_success
...
â
TEST PASSED: invalid_email
Editor Support â
Install the VS Code Extension
GitHub Repo for Extension
Features:
- Syntax highlighting
- Snippet auto-completion
- Section folding
- Real-time validation