Sprint.Java Testing Framework Junit

less than 1 minute read

일단 이거 참고
이클립스에 이 부분 기본 설정 후
http://memo.polypia.net/archives/557

public static workTest{
  @Before
  public void before1(){
  }

  @After
  public void after1(){
  }

  @Test
  public void test1(){
    Web web = new Web();
    //이런게 있다고 치고....
    x = web.getX();
    //3이 나오면 성공
    assertThat(x, is(3));
  }

  @Test(expected=JDBCException.class)
  public void test2() throws Exception{
    //JDBC익셉션이 발생하는 그코드
  }
}

assertThat(x, is(3));
assertThat(x, is(not(3)));
assertThat(responseString, either(containString)););
assertThat(list, hasItem("3"));

대강 이정도면 다됨
@Rule이라는건 필요할 때가되면

스프링 설정

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
		locations = {
				"classpath:spring-context.xml"
		}
)