GithubHelp home page GithubHelp logo

Comments (2)

mrserverless avatar mrserverless commented on July 3, 2024

If you want to test end to end functionality without Mocks, you would be better off doing a integration test, see: InjectedIntegrationTest. Use the code you had in #61 and delete the setUp() method and it should run. Put your setup logic inside the TestModule which is called by TestApplication

ResourceTestRule is for unit testing your Resource logic only, it expects a mocked DAO. You are right in saying that Guice hasn't run. To brute force it you can do something like this:

   final static Injector injector = Guice.createInjector(new TestModule());
   static DaoResource daoResource = injector.getInstance(DaoResource.class);

   @ClassRule
   public static final ResourceTestRule resources = ResourceTestRule.builder()
            .addResource(daoResource)
            .build();

I don't know what you DAO looks like, but your TestModule needs to provide all the necessary dependencies needed by your DAO. It's not easy creating a Hibernate SessionFactory from scratch, but for JDBI you can refer to this gist: https://gist.github.com/yunspace/b50b5b89bc1bad1fa556

It would be helpful you can ask questions using your own code or a gist. Takes away the guess work and saves some time for all of us.

from dropwizard-guice.

patricioe avatar patricioe commented on July 3, 2024

Thank you Yun. I'm using my own MongoDBDAO, not really using dropwizard db
support at the moment.

On Mon, Jul 20, 2015 at 7:13 AM, Yun Zhi Lin [email protected]
wrote:

If you want to test end to end functionality without Mocks, you would be
better off doing a integration test, see: InjectedIntegrationTest. Use
the code you had in #61
#61 and delete the
setUp() method and it should run. Put your setup logic inside the
TestModule which is called by TestApplication

ResourceTestRule is for unit testing your Resource logic only, it expects
a mocked DAO. If you want to test a real DAO, Guice can't magically
inject in the configurations when they don't exist. You will need to do
something like this https://gist.github.com/yunspace/b50b5b89bc1bad1fa556.
What DAO are you using anyway? Hibernate or JDBI?


Reply to this email directly or view it on GitHub
#62 (comment)
.

from dropwizard-guice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.