Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Robolectric - how to disable a unit test?

I have a robolectric unit test that is work in progress. I want to disable it temporarily pending implementation, but I don't want to comment out the entire test.

How can a robolectric unit test be temporarily disabled without actually removing the test?

like image 350
CJBS Avatar asked Jul 16 '15 18:07

CJBS


People also ask

What are the disadvantages of using Robolectric?

The downside is that it fakes an Android environment which you should be aware of. To validate real world problems, better use a classic Android Framework approach. The best is still to write your code in a way that you can unit test it and that you don't need a context or any other Android framework dependencies.

Is Robolectric deprecated?

setupActivity() is deprecated in Android unit test. Save this question.

What is the difference between Mockito and Robolectric?

Mockito is used for mocking the dependency which means if you want to access an real object in test environment then you need to fake it or we can say mock it. Now a days it is very easier to do mocking of the objects with Mockito. Roboelectric is the industry-standard unit testing framework for Android.


2 Answers

The JUnit @Ignore attribute can be used to temporarily disable a unit test:

@RunWith(MyRobolectricGradleTestRunner.class)
public class TestAbc123 extends MyTestBase
{
    @Ignore   // This attribute may be removed once the test is ready
    @Test
    public void TestAbc123Scenerio1()
    {

Ignored tests are shown as an amber disc with horizontal bars:

Ignored test output

like image 111
CJBS Avatar answered Oct 18 '22 23:10

CJBS


To ignore a Unit test, annotate it with @Ignore.

You can add an optional comment to record why the test is being ignored:

@Ignore("Not ready yet")
@Test
public void testToIgnore()
{
    // ...
}
like image 3
Regis Avatar answered Oct 19 '22 00:10

Regis