Injection and integrated tests

16 views
Skip to first unread message

Danil Suits

unread,
Nov 9, 2016, 2:47:12 PM11/9/16
to testng-users
TL;DR how do I configure integration/specification testing of third party service providers?

I've found a few pages on-line describing working with Guice modules in tests, but I couldn't tell from the descriptions that they would fit this use case:

Alice publishes a jar with a service provider interface

public interface Frobozz {
   
int xyzzy (long arg);
}

and a specification (which is where I think I'm having the trouble)

Enter code here...
public class FrobozzSpecification {
   
@Inject
    Frobozz systemUnderTest;

   
@Test
    void checkCompliance (long arg , int expected) {

       
int actual = systemUnderTest.xyzzy(arg);
       
Assert.assertEquals(actual, expected);
   
}

   
// ...
}

Bob publishes a jar with a service provider that implements the interface

Enter code here...
public class Zork implements Frobozz {
   
public int xyzzy(long arg) {
       
return 0;
   
}
}

Both Bob and Alice should be able to take the two (closed) jars, and check that the Zork implementation conforms to the FrobozzSpecification.

How is that supposed to work? 
Does Alice need to add additional affordances to the interface or the specification?
Does the answer change if Alice annotates the interface with @ImplementedBy which specifies a reference implementation that she provides?

I think I've figured out that I can implement IObjectFactory, collect a bunch of guice modules inside it, and then use the -objectfactory command line argument to switch to an ObjectFactory that overrides new Instance, constructs a instance of the specification, and then uses an injector to wire everything together.

I keep looking for a more direct answer - am I supposed to be able to do this one @Guice(module) @Guice(moduleFactory)?  I dig, but the examples I've found all suggest that the classes used to satisfy the annotations on FrobozzSpecification need to be visible when we build Alice's binary, which means that we don't have access to Bob's implementation or his module.  I don't have enough laps to know if IObjectFactory is my answer, or if I'm just missing something obvious.

Thanks!
Reply all
Reply to author
Forward
0 new messages