상세 컨텐츠

본문 제목

[Junit4] containsString, both, either

Junit4

by kwanghyup 2020. 6. 18. 01:53

본문

import org.junit.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

public class SampleTest {

    @Test
    public void test_containsString(){
        String actual = "terran";
        assertThat(actual, containsString("rr"));
    }


    @Test
    public void test_both_either() {
        String actual = "albumen";

        // both A and B
        assertThat(actual, both(containsString("a"))
                .and(containsString("b"))
                .and(containsString("e"))
                );

        // either A or B 
        assertThat(actual, either(containsString("u"))
                .or(containsString("Z"))
                .or(containsString("p")
                ));
    }

}

관련글 더보기

댓글 영역