03 | 기타 테스트 애너테이션
스프링 프레임워크는 더 많은 테스트 애너테이션을 제공한다. 몇 가지 예제를 살펴보자. 예제 7-8은 SpringJUnit4ClassRunner 또는 JUnit 지원 클래스를 이용할 때만 사용할 수 있는 @Timed와 @Repeat 애너테이션을 보여준다.
예제 7-8 MyDocumentsMoreAnnotationsTest.java(@Timed, @Repeat)
package com.apress.isf.spring.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Timed;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.apress.isf.java.model.Document;
import com.apress.isf.java.model.Type;
import com.apress.isf.java.service.SearchEngine;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:META-INF/spring/mydocuments-context.xml")
public class MyDocumentsMoreAnnotationsTest {
private static final Logger log =
LoggerFactory.getLogger(MyDocumentsMoreAnnotationsTest.class);
@Autowired
private SearchEngine engine;
@Autowired
private Type webType;
@Timed(millis=2000)
@Test
public void testUsingSpringTimedAnnotationTest() throws InterruptedException {
log.debug("Using Spring Test fixtures:");
List<Document> documents = engine.findByType(webType);
assertNotNull(documents);
assertTrue(documents.size() == 1);
assertEquals(webType.getName(), documents.get(0).getType().getName());
assertEquals(webType.getDesc(), documents.get(0).getType().getDesc());
assertEquals(webType.getExtension(),
documents.get(0).getType().getExtension());
Thread.sleep(500);
documents = engine.listAll();
assertNotNull(documents);
assertTrue(documents.size() == 4);
}
@Repeat(10)
@Test
public void testUsingSpringRepeatedAnnotationTest() {
log.debug("This message should be printed 10 times..");
}
}