2

I am working in android studio. I'm training to understand how to do unit testing. when I run my test i have this error: java.lang.RuntimeException: Method i in android.util.Log not mocked. See http://g.co/androidstudio/not-mocked for details.

thank in advance.

    package com.bignerdranch.android.beatbox;

import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class SoundViewModelTest {
    private BeatBox mBeatBox;
    private Sound mSound;
    private SoundViewModel mSubject;

    @Before
    public void setUp() throws Exception {
        mBeatBox = mock(BeatBox.class);
        mSound = new Sound("assetPath");
        mSubject = new SoundViewModel(mBeatBox);
        mSubject.setSound(mSound);
    }

    @Test
    public void exposesSoundNameAsTitle() {
        assertThat(mSubject.getTitle(), is(mSound.getName()));
    }


}
snailp4el
  • 153
  • 1
  • 15
  • Does this answer your question? [How to mock method e in Log](https://stackoverflow.com/questions/36787449/how-to-mock-method-e-in-log) – Vadim Kotov Jan 17 '20 at 16:00

1 Answers1

1

I use PowerMock for this. Before you declare your test class you have to put the following:

@RunWith(PowerMockRunner.class)
@PrepareForTest({Log.class})

And then, inside the @Before method:

PowerMockito.mockStatic(Log.class);
Julio Garcia
  • 1,904
  • 16
  • 26