Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android JUnit Testing, cannot resolve is(boolean) in assertThat?

in build.gradle

dependencies {    
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
}

Code

import com.myapp.LVActivity;
import org.junit.Test;
import static org.junit.Assert.*;

public class DeviceUnitTest {
    @Test
    public void check_that_is_correct_device_name_isTrue() {
        assertThat(LVActivity.isCorrectDevice("MySpecialDevice"), is(true));
    }
}

In LVActivity:

private final static String correctName = "MySpecialDevice";
public static boolean isCorrectDevice(String deviceName) {
    return deviceName.equals(correctName);
}

The error is here:

is(true)

Error:

Cannot resolve method is(boolean)

I am trying to do a simple local unit test.

I'm following this tutorial http://developer.android.com/training/testing/unit-testing/local-unit-tests.html

like image 895
Adz Avatar asked Oct 24 '25 04:10

Adz


1 Answers

Wouldn't you rather just say:

import static org.junit.Assert.*;

assertTrue(LVActivity.isCorrectDevice("MySpecialDevice"));

This is a more natural expression for checking a boolean.

But if you need to use the is matcher with assertThat, you will need this import:

import static org.hamcrest.CoreMatchers.*;
like image 115
Doug Stevenson Avatar answered Oct 25 '25 16:10

Doug Stevenson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!