Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run unit tests on Save with Android Studio

Has anyone managed to make a reasonably comfortable setup for their project where unit tests run on every save?

I currently have a split project -- An Android Application project, and a Java project that the android application depends upon. I write unit tests for the Java project and run them manually every now and then.

In my understanding, to make this happen as expected, I also want to have incremental builds for the Java project. I am not sure that this is feasibly possible while using Gradle with its current state of affairs.

like image 395
Ben Barkay Avatar asked Sep 05 '15 08:09

Ben Barkay


People also ask

How do I make unit tests automatically?

To generate unit tests, your types must be public. Open your solution in Visual Studio and then open the class file that has methods you want to test. Right-click on a method and choose Run IntelliTest to generate unit tests for the code in your method. IntelliTest runs your code many times with different inputs.

How do I run a unit test file?

To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).

Which directory is used to store unit tests in your Android project?

By default, the source files for local unit tests are placed in module-name/src/test/ . This directory already exists when you create a new project using Android Studio.


1 Answers

If you are using Eclipse or IntelliJ with JUnit, you can use InfiniTest to run tests on save. InfiniTest only runs tests for code that has changed rather than running everything, so it's great for TDD. InfiniTest is completely decoupled from Gradle, so you don't have to worry about incremental builds.

like image 147
Tom N. Avatar answered Sep 23 '22 10:09

Tom N.