question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best practices for Integration Tests on a Java Client application

See original GitHub issue

I am looking for some suggestion about creating integration (unit) tests for a client application written in Java.

Ideally I would like to start an in memory Standalone Pravega service.

 try (PravegaStandaloneForTests server = bootPravegaStandaloneForTests() {   
  String  connectionString = server.getConnectionString();
   run application that writes/reads to Pravega....
}

Context: We are going to implement an integration between Pravega and EmailSuccess.com, EmailSuccess.com will be a source of data, it will write a stream of events to Pravega. We want to create integration tests with JUnit.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
eolivellicommented, May 18, 2020

@ravisharda this is my working test

https://github.com/eolivelli/pravega-testing/blob/master/src/test/java/PravegaIntegrationTest.java

This is the minimal set of dependencies: https://github.com/eolivelli/pravega-testing/blob/master/pom.xml

Issues:

  • you need to explicitly clean up netty dependencies, from the dependency tree you got several versions, with and without the ‘-all’ suffix
  • you need to explicitly add grpc

I didn’t have to add pravega-shared-authplugin, maybe it is automatically imported by the java client, that you need in order to make any meaningfull test

Regarding the ‘start’ method I can raise a PR. Regarding the dependencies I prefer that someone expert of the release process would do it. It would be very good to have some integration tests that create a simple project like the one on my github. Something that is “far” from Pravega codebase and this way we are sure that it is not affected by transitive dependencies injected by parent modules

0reactions
ravishardacommented, May 18, 2020

@eolivelli

Can you please confirm that correct Maven dependency for tests is this one ?

A second dependency in addition to the one you mention will be needed. Both of these are required:

  1. io.pravega:pravega-standalone:0.7.0
  2. io.pravega:pravega-shared-authplugin:0.7.0

(That using Pravega standalone requires the second one, is a bug. Previously, the first one was sufficient. I’ve created issue 4795 for this.)

I see that LocalPravegaEmulator#start is not “public”. But we can call it using Java reflection. We can make it public. Once we have finished the first run of integration tests I will send a PR in order to make it public

Yes, that’s an issue. We should make it public so that people can use the LocalPravegaEmulator. Would you consider raising a pull request for it?

In the meantime, you can use the InProcPravegaCluster that the LocalPravegaEmulator uses internally. Something like this:

 InProcPravegaCluster inProcCluster = InProcPravegaCluster.builder()
                .isInProcZK(true)
                .zkUrl("localhost:" + 2181)
                .zkPort(2181)
                .isInMemStorage(true)
                .isInProcController(true)
                .controllerCount(1)
                .enableRestServer(true)
                .restServerPort(9091)
                .controllerPorts(new int[]{9090})
                .isInProcSegmentStore(true)
                .segmentStorePorts(new int[]{6000})
                .segmentStoreCount(1)
                .containerCount(4)
                .enableTls(false)
                .enableAuth(false)
                .build();

       inProcCluster.start();
       
      // Add test logic

       inProcCluster.close();

cc @derekm

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 best practices for integration testing with continuous ...
1. Do integration testing before unit testing · 2. Don't test business logic with integration testing · 3. Know why integration testing is...
Read more >
Modern Best Practices for Testing in Java - Philipp Hauer's Blog
This post contains many best practices that I collected over the years of writing unit tests and integration tests in Java.
Read more >
Test a REST API with Java - Baeldung
In this tutorial, we'll focus on the basic principles and mechanics of testing a REST API with live Integration Tests (with a JSON...
Read more >
Build with Confidence: A Guide to JUnit Tests - Toptal
We will focus on writing unit and integration testing for a web app written in Java's Spring framework. Most of the time, we...
Read more >
Integration Testing Tools and Practices to Start Using Today
Best Practices of Integration Testing · Determine test data correctly. · Prepare test data in parallel with writing test cases or at least...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found