Skip to content

a-simeshin/allure-grpc

Repository files navigation

allure-grpc

License CodeStyle CodeAnalysis Docs

Lightweight gRPC interceptors to attach integration data into Allure reports

Client interceptor

The client interceptor designed to attach maximum of useful integration data from the gRPC client to Allure, that could be helpful to visually display possible problems that occur in tests without repeated broken or failed tests on CI. Supports unary and stream interactions. Interceptor converts and formats messages from proto to more readable json format by default.

Usage

For additional examples look at grpc-java examples

    YourServiceGrpc.YourServiceBlockingStub yourServiceBlockingStub = YourServiceGrpc.newBlockingStub(
        ManagedChannelBuilder.forAddress(host, port)
            .intercept(new AllureGrpcClientInterceptor())
            .build()
    );

for in-process client-server interaction

    YourServiceGrpc.YourServiceBlockingStub yourServiceBlockingStub = YourServiceGrpc.newBlockingStub(
        InProcessChannelBuilder.forName("testing")
            .intercept(new AllureGrpcClientInterceptor())
            .build()
    );

For additional examples look at client configuration

@Configuration
@GrpcClientBean(
        clazz = YourServiceGrpc.YourServiceBlockingStub.class,
        beanName = "yourServiceBlockingStub",
        client = @GrpcClient(value = "testing", interceptors = AllureGrpcClientInterceptor.class)
)
public class ClientTestConfiguration {
}

or

@Configuration
@GrpcClientBean(
        clazz = YourServiceGrpc.YourServiceBlockingStub.class,
        beanName = "yourServiceBlockingStub",
        client = @GrpcClient(value = "testing")
)

public class ClientTestConfiguration {

    @Bean
    GlobalClientInterceptorConfigurer globalClientInterceptorConfigurer() {
        return interceptors -> interceptors.add(new AllureGrpcClientInterceptor());
    }
}

or

@Configuration
@GrpcClientBean(
        clazz = YourServiceGrpc.YourServiceBlockingStub.class,
        beanName = "yourServiceBlockingStub",
        client = @GrpcClient(value = "testing")
)

public class ClientTestConfiguration {

    @GrpcGlobalClientInterceptor
    AllureGrpcClientInterceptor allureGrpcClientInterceptor() {
        return new AllureGrpcClientInterceptor();
    }
}

Client bean access in tests

@EnableAutoConfiguration
@SpringBootTest(
        classes = ClientTestConfiguration.class,
        properties = {
                "grpc.server.port=0",
                "grpc.client.GLOBAL.negotiationType=PLAINTEXT",
                "grpc.client.testing.address=self:self"
        }
)
public class AttachToAllureTest {

    @Autowired
    YourServiceGrpc.YourServiceBlockingStub yourServiceBlockingStub;
}

Additional configuration

Interceptor converts and formats messages from proto to more readable json format by default, but if you want to display the original proto messages as string then static field provided.

    @BeforeEach
    public void setUpFormatter() {
        //true by default
        ProtoFormatter.FORMAT_PROTO_TO_JSON = false;
    }

About

gRPC interceptors to attach integration data into Allure reports

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages