Anwar Shaikh
Anwar Shaikh

Reputation: 104

Android unit testing for own android library

I have developed android library which do not have any UI component . It contains services ,methods etc.

Now i want to write unit test cases for my library , but I am unaware about how to start,what are the best practices , any framework to use .

I read android documentation , but could not really understand

Can anyone help regarding this ?

Thanks in advance.

Upvotes: 0

Views: 857

Answers (2)

Mamunur Rahman Hera
Mamunur Rahman Hera

Reputation: 116

Try Mockito. I hope it will be easy to understand and implement.

Android Unit Testing with Mockito https://www.raywenderlich.com/174137/android-unit-testing-with-mockito

With TestMe(IntelliJ plugins for Android Studio to generate Unit Testing code very easily)

TestMe (https://plugins.jetbrains.com/plugin/9471-testme)

Auto Generate Unit Tests for source class in Java or Groovy. No more boilerplate!

Features:

  • Auto-generate Java or Groovy test code with JUnit 4/5, TestNG or Spock frameworks
  • Auto-generate Mockito mocks
  • Generate test params and assertion statements

Quick-Start: http://weirddev.com/testme/

Upvotes: 1

Sid
Sid

Reputation: 1274

You can choose to write either android testcases which run on a device or emulator, or you can go ahead and write unit tests which run on the local JVM. I would suggest that you go fir android tests as you might be using android libraries and in this way you will avoid mocking a lot of dependencies.

In case you require any dependencies for your tests, then you can add them like below in your gradle file:

androidTestCompile 'org.mockito:mockito-core:1.10.8' ---for android testcases testCompile 'com.google.dexmaker:dexmaker-mockito:1.1' ---for local test cases

Also for startig just right click on any file that you want to unit test and in Go To option select test and then select create new test.

Also you can refer the below links. I found them very useful for my unit testing:

http://vexdev.com/2015/05/06/unit-testing-android/

https://www.toptal.com/android/testing-like-a-true-green-droid

Upvotes: 1

Related Questions