The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Testing the MVI Flow

You should be able to run the RepoTests and confirm that they still work, as we have not made material changes to the repository… yet. We will be revising it a fair bit coming up in a future tutorial, as we start to save our items in a database.

However, we should start testing some of our other functionality. In this tutorial, we will write a ControllerTest test class and method for testing our Controller, ensuring that it can receive actions and publish results.

This is a continuation of the work we did in the previous tutorial. The book’s GitHub repository contains the results of the previous tutorial as well as the results of completing the work in this tutorial.

Step #1: Adding a ControllerTest Class

We need to add a new Java class, which you have done many times already. However, this time, we need to add it to the androidTest source set, not to the main source set.

Right-click over the com.commonsware.todo package in the java/ directory in the androidTest source set, where you have RepoTests. Choose “New” > “Java Class” from the context menu. For the name, fill in ControllerTest. Click OK to create the class, giving you:

package com.commonsware.todo;

public class ControllerTest {
}

Then, add the @RunWith(AndroidJUnit4.class) that we have on RepoTests to ControllerTest, giving you:

package com.commonsware.todo;

@RunWith(AndroidJUnit4.class)
public class ControllerTest {
}

Next, add a stub @Test method, named controller(), giving you:

package com.commonsware.todo;

@RunWith(AndroidJUnit4.class)
public class ControllerTest {
  @Test
  public void controller() {

  }
}

If you run ControllerTest via the double-play icon in the gutter next on the public class ControllerTest line, it should run successfully… albeit while not testing anything.

Step #2: Setting Up a Controller

The preview of this section was fed to a gremlin, after midnight.

Step #3: Testing the Initial Load

The preview of this section may contain nuts.

Step #4: Testing Adds

The preview of this section was last seen in the Bermuda Triangle.

Step #5: Testing Modifications

The preview of this section is [REDACTED].

Step #6: Testing Deletions

The preview of this section is in an invisible, microscopic font.

What We Changed

The preview of this section is sleeping in.