lundi 30 novembre 2015

Android PointF constructor not working in JUnit test

I have just stumbled on this while trying to write a JUnit test. Admittedly this is my first unit test in JUnit, but I do find the behaviour very puzzling.

package com.example.dom.pointfbugrepro;

import android.graphics.PointF;
import org.junit.Test;
import static org.junit.Assert.*;

public class ExampleUnitTest {
    @Test
    public void pointf_isCorrect() throws Exception {
        PointF foo = new PointF(5, 0);
        assertEquals(5, foo.x, 0.0001f);
    }
}

Running this test in a brand new Android Project results in an assertion failure:

java.lang.AssertionError: 
Expected :5.0
Actual   :0.0

One thing I found out while investigating this problem is that assigning to the PointF instance's x field directly does work.

So what is the problem here? Why doesn't the constructor set the fields properly? and how should I be testing classes which use the PointF Android class?

Aucun commentaire:

Enregistrer un commentaire