Get "No implementation for ... was bound." error while trying to use Guiceberry with junit4 test which extends TearDownTestCase

42 views
Skip to first unread message

Junyi Wen

unread,
Apr 14, 2016, 11:47:49 AM4/14/16
to guiceberry-users
Hi,

     I'm holding onto the Guiceberry tutorial and create this junit3 test using Guiceberry, but it's throwing the following exception:



java.lang.RuntimeException: Binding error in the GuiceBerry Env 'com.google.ads.api.services.testing.functional.FunctionalTestGuiceberryEnvironment': 'Guice configuration errors:

1) No implementation for com.google.ads.common.constants.CurrencyRepository was bound.
  while locating com.google.ads.common.constants.CurrencyRepository
    for field at com.google.ads.api.services.testing.functional.tests.datax.DataxServiceTest.currencyRepository(DataxServiceTest.java:52)
  while locating com.google.contentads.usertargeting.datax.pubsub.ddpsharelists.DdpShareListsActionTest

1 error'.
	at com.google.guiceberry.GuiceBerryUniverse$TestCaseScaffolding.injectMembersIntoTest(GuiceBerryUniverse.java:175)
	at com.google.guiceberry.GuiceBerryUniverse$TestCaseScaffolding.runBeforeTest(GuiceBerryUniverse.java:117)
	at com.google.inject.testing.guiceberry.junit3.GuiceBerryJunit3.doSetUp(GuiceBerryJunit3.java:155)
	at com.google.inject.testing.guiceberry.junit3.GuiceBerryJunit3.setUp(GuiceBerryJunit3.java:136)
	at com.google.ads.api.services.testing.functional.AbstractServiceTest.doGuiceBerryJunit3SetUp(AbstractServiceTest.java:221)
	at com.google.ads.api.services.testing.functional.AbstractServiceTest.setUp(AbstractServiceTest.java:174)
	at com.google.ads.api.services.testing.functional.tests.datax.DataxServiceTest.setUp(DataxServiceTest.java:89)
	at com.google.contentads.usertargeting.datax.pubsub.ddpsharelists.DdpShareListsActionTest.setUp(DdpShareListsActionTest.java:100)
	at com.google.common.testing.junit3.TearDownTestCase.runBare(TearDownTestCase.java:116)


===============================================================================================
DdpShareListsActionTest.java

package com.google.contentads.usertargeting.datax.pubsub.ddpsharelists;
...
/**
 * An integration test for {@link DdpShareListsAction}.
 */
@ApiServices(
    value = {UserListClientService.class, UserListService.class, DdpCustomerMappingService.class})
@GuiceBerryEnv(GuiceberryEnvironmentNames.FUNCTIONAL_ENVIRONMENT)
@LargeTest
public class DdpShareListsActionTest extends DataxServiceTest {
  private static class NoDryRunModule extends AbstractModule {
    @Override
    protected void configure() {
      bind(Key.get(Boolean.class, Names.named("dryRun"))).toInstance(false);
    }
  }
  protected DdpCustomerMappingService ddpCustomerMappingService;
  protected UserListClientService userListClientService;
  protected DdpShareListsAction ddpShareListsAction;
  protected final String scionUserListName = "ScionUserList";
  protected final String mccUserListName = "MccUserList";
  protected ApiTestAdvertiser scionOwnerCustomer;
  protected ApiTestAdvertiser mccManagerCustomer;
  protected ApiTestAdvertiser clientCustomer;
  protected List<UserList> testScionUserLists;
  protected List<UserList> testMccUserLists;
  protected int userListNameSuffix = 1;
  protected BoulderTestingEnvironment boulderEnv;

  private TearDown toTearDown;

  public DdpShareListsActionTest() {
    boulderEnv = new BoulderTestingEnvironment();
    addEnvironment(boulderEnv);
  }

  @Override
  public void setUp() throws Exception{
    super.setUp();
    toTearDown = ManualTearDownGuiceBerry.setUp(this, DdpGuiceberryEnv.class);
    Injector injector = boulderEnv.getInjector();
    tas = injector.getInstance(ApiTestAdvertiserService.class);
    ddpCustomerMappingService = makeClient(DdpCustomerMappingService.class);
    userListClientService = makeClient(UserListClientService.class);
    userListService = makeClient(UserListService.class);

    ddpShareListsAction = new DdpShareListsAction(
        userListClientService,
        userListService,
        ddpCustomerMappingService,
        false,
        200);
    
    scionOwnerCustomer = dtas.createAdvertiserForExternalSystem(
        new TestAdvertiserData(), Product.SCION);
    mccManagerCustomer = dtas.createAdvertiserWithIds(
        new TestAdvertiserData().whitelistForFeature(ProductFeature.LICENSED_USER_LISTS_TAB));
    clientCustomer = dtas.createAdvertiserWithIds(
        new TestAdvertiserData().whitelistForFeature(ProductFeature.LICENSED_USER_LISTS_TAB));
    dtas.setNamedInjectableValue("systemAccountsCustomerIdSet",
        Long.toString(scionOwnerCustomer.getCustomerId()));
    testScionUserLists = createUserLists(
        scionUserListName, scionOwnerCustomer, 2, EntityNamespaceSubtype.SCION_APP, 1000L);
    List<UserList> testMccUserLists = createUserLists(
        mccUserListName, mccManagerCustomer, 2, null, null);
    addTearDown(new TearDown() {

      @Override
      public void tearDown() throws Exception {
        toTearDown.tearDown();
      }
    });
  }

....

}

Luiz-Otavio Zorzella

unread,
Apr 14, 2016, 12:50:56 PM4/14/16
to guiceber...@googlegroups.com
Junyi,

I think you meant to post this in google's internal mailing list. Your subject should also be junit3, not junit4.

Without looking deeply into this, it seems like you are using two distinct frameworks that give you an injector -- GuiceBerry and this BoulderTestingEnvironment. The latter is the one complaining about the missing binding.

This mixture in the test looks very suspicious (i.e. it's probably not what you want to do): I would reach out to your co-workers to get this sorted out.

Z

--
You received this message because you are subscribed to the Google Groups "guiceberry-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guiceberry-use...@googlegroups.com.
To post to this group, send email to guiceber...@googlegroups.com.
Visit this group at https://groups.google.com/group/guiceberry-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages