No description, website, or topics provided.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Robolectric Katas

Use this repository a starting point to complete Android code katas.

Join my newsletter for updates about my upcoming book with Android katas.


The master branch has Robolectric preintegrated.

Note: To become comfortable with integrating Robolectric, use the "Hello, Robolectric" chapter of the Android Activity Book or my Pocket Guide to TDD with Robolectric (coming soon!) as a separate kata.

Simply import into Android Studio using the "Import Non-Android Studio project" option and selecting the top-level build.gradle file.

Import project

Test Artifact

In Android Studio, open the "Build Variants" tab and select "Unit Tests" as the "Test Artifact" and debug from the drop down next to app.

Run Tests

Now that the project is set up, ensure the tests run.

Create a run configuration to run the tests from the IDE (my preferred method). Click the plus button, select "junit," and match the configuration shown here:

Run Configuration

You can also run the tests from the command line, using ./gradlew check.

Now that the project is configured, you're ready to work though some katas!


Junit Runtime Scope

If you get this error when using your run configuration, you used the wrong module name in your classpath when you configured it.

10:15:14 AM Error running Unnamed: No junit.jar in Module 'AndroidKatas' runtime scope

Change it to use app instead of AndroidKatas.

NoClassDefFoundError: ResultPrinter

If you get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(
	at com.intellij.rt.execution.application.AppMain.main(
Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
	at Method)
	at java.lang.ClassLoader.loadClass(
	at sun.misc.Launcher$AppClassLoader.loadClass(
	at java.lang.ClassLoader.loadClass(
	... 3 more

Process finished with exit code 1

It means that you forgot to select "Unit Tests" as the "Test Artifact" in the "Build Variants" window.