Big O Big O - 9 months ago 43
Android Question

How to configure and run a Mockito test

I am working on an Android app which has some pure java based components that i want to test using Mockito.

I have some questions about configuring Mockito with my code base.

  1. Should I create a test project in my code base?

  2. Does Mockito has anything to do with JUnit? Do i need to include JUnit libs as well?

  3. How do i run the Mockito test from Eclispe as opposed to JUnit test which is far more easier to run by doing Run As-> JUnit Test.

Kindly suggest some tutorial that could demo the setup and running of tests.

Answer Source
  1. You don't need to create a separate test project, but you can if you want to. Most people do it by creating a separate test folder in the same project. Whether you have a separate test project or just a test folder, you should replicate your package structure inside your test folder, so that each test class is testing an application class in the same package.
  2. Yes. Mockito is designed to be used with JUnit, or with some other testing framework, such as TestNG. Most people use it with JUnit. Most of the examples on the Mockito web site use JUnit. So, yes, you'll need the JUnit libraries, or the libraries for whatever other testing framework you choose.
  3. A Mockito test is a JUnit test (or a TestNG test, or whatever). So there's no "far more easier to run", as you put it. Just write a JUnit test that uses Mockito, and run it in the same way as any other JUnit test.
  4. Start with the Mockito web site.