반응형
    
    
    
  @RunWith(ParameterizedRobolectricTestRunner.class)
public class ContactServiceTest {
    @ParameterizedRobolectricTestRunner.Parameters(name = "ErrorCode = {0}")
    public static Collection data() {
        return Arrays.asList(new Object[][]{
                {105, 105_ERROR_MSG},
                {113, 113_ERROR_MSG},
                {114, 114_ERROR_MSG},
                {134, 134_ERROR_MSG},
                {137, 137_ERROR_MSG},
                {999, DEFAULT_ERROR_MSG} // Bogus error code
        });
    }
    private int errorCode;
    private String expectedErrorMsg;
    public ContactServiceTest(int errorCode, String errorMsg) {
        this.errorCode = errorCode;
        this.expectedErrorMsg = errorMsg;
    }
    @Test
    public void when_known_error_code_is_received_from_service_correct_error_msg_is_displayed_to_user() {
        // HTTP response from service contains defined error code
        Robolectric.addPendingHttpResponse(HttpStatus.SC_OK, buildFakeServiceResponse(errorCode)); 
        // Contact the service
        mService.contactService();
        // Use awaitility to wait until error message is displayed to user
        // then assert that the error message is correct
        await().until(getDisplayedErrorMsg(), is(expectedErrorMsg));
    }
https://blog.jayway.com/2015/03/19/parameterized-testing-with-robolectric/
Parameterized testing with Robolectric - blog.
In our current project we are using Robolectric when writing unit tests for our Android application and it has been working out really well. Recently I needed to write a test case that performed an operation several times, but with different test data, and
blog.jayway.com
반응형
    
    
    
  'Applied > Unit Test' 카테고리의 다른 글
| [JUnit] Test Rule 개념 및 코드 (0) | 2020.04.25 | 
|---|---|
| [Robolectric] robolectric shadow bitmap 관련 참고 코드 (0) | 2020.04.21 | 
| [JUnit] exception 테스트 하는 방법 (0) | 2020.03.01 | 
| [JUnit] private 메서드, 변수 테스트 방법 (1) | 2020.02.29 | 
| [JUnit] hamcrest를 이용한 test code 만들기 (0) | 2020.02.08 |