mercredi 30 décembre 2015

Can't get JUnit tests to fail in Android Studio

I'm trying out Android development, but haven't come too far because I'm unable to get a test case to fail.

I have the following test case in the androidTest folder:

package com.example.aaronf.myapplication;

import android.test.*;

public class ToDoListTest extends AndroidTestCase {

    private void newToDoListHasNoItems() {
        assertEquals(new ToDoList().length, 0);
    }

    private void addingToDoGivesLengthOfOne() {
        ToDoList toDoList = new ToDoList();
        toDoList.add(new ToDo());
        assertEquals(toDoList.length, 1);
    }

    public void runTests() {
        newToDoListHasNoItems();
        addingToDoGivesLengthOfOne();
    }

    public ToDoListTest() {
        super();
        runTests();
    }
}

The ToDoList class looks like:

package com.example.aaronf.myapplication;

public class ToDoList {
    public int length = 0;

    public void add(ToDo toDo) {

    }
}

It seems like it should fail on addingToDoGivesLengthOfOne(), but I get a green bar.

Aucun commentaire:

Enregistrer un commentaire