TmTron
TmTron

Reputation: 19421

Robolectric different threads in Android Studio vs. Gradle tests

why are thread names different when I start a Robolectric test from Android Studio vs. the Gradle build?

e.g. consider this simple test:

@RunWith(RobolectricTestRunner.class)
public class RobolectricRxThreadTest {
    @Test
    public void testMainThreadName() {
        assertEquals("main", Thread.currentThread().getName());
    }
}

when I start this test

Upvotes: 1

Views: 277

Answers (1)

Eugen Martynov
Eugen Martynov

Reputation: 20140

I just reproduced the issue, but I wonder why do you need this test?

If you really want to check main thread then the correct way would be:

 assertThat(Thread.currentThread()).isEqualTo(Looper.getMainLooper().getThread());

And this test pass from AS and console both runs.

Upvotes: 1

Related Questions