15
Jun

How to Configure Junit Testing Framework in Android Studio

How to Configure Junit Testing Framework in Android Studio?


In our previous post, we talked about the Android Studio and Java Installation. In this we will learn about very famous unit testing framework setup for android studio that is Junit. Before jumping on to the setup let us learn more about Junit Testing Framework.

What is Junit ?

Junit is a widely used testing framework used for Java Programming language. Before you learn, how to write automated test cases it is very important to learn Junit testing framework in detail. It helps you to define the flow of your testing framework.
Junit is built on idea of “first testing and then coding” which helps in increasing productivity of the test case developer and stability of the code.

 

Features of Junit Testing –

  • It is open source testing framework allowing users to write and run test cases effectively.
  • Provides various types of annotations to identify test methods.
  • Provides different types of Assertions to verify the results of test case execution.
  • It also gives test runners for running tests effectively.
  • It is very simple and hence saves time.
  • It provides ways to organize your test cases in form of test suits
  •  You can integrate Junit with Eclipse, Android Studio, Intellij etc.

How to Setup JUnit–

    • Create a new Project in Android Studio – (Refer our previous post)
      • Go to app -> build.gradle
      • In the file add below line of code in dependencies section:
        • testCompile group: ‘junit’, name: ‘junit’, version: ‘4.12’

     

      • Click on SyncJunit
      • Once you get Build is Successful message then your Junit Framework is Set and you can use it while writing your test cases
      • Note – We will see how to use Junit in your test cases in our future posts