에버노트 정리 원본 (사진포함)
==> https://www.evernote.com/shard/s350/sh/5da25168-e641-4739-9265-85e304f83582/1d1f613e5e504641e35df5a3c48e8e0b
----------------------------------------------------------------------------------------------------------------
2017.04.11 화
JUnit : 단위테스트를 지원하는 프레임워크
* API 주소 : (http://junit.org/junit4/javadoc/latest/)
1. JUnit Library 준비
2. POJO형태의 Java 클래스 작성
@Before
- 테스트 메서드를 수행하기전에 꼭 해야하는것들(초기화)
@Test
- 반드시 접근public, 리턴타입 void
Assert.assertSame(expected, actual);
//assert는 static이기때문에,
import static org.junit.Assert.assertSame; 작성후 assertSame으로 사용가능
//(arg1,arg2)
expected
: 기대되어지는 결과문자열 /
actual
: 실행값 /equals라고 생각하면됨->true 반환시 성공함
@After
- 테스트 후처리 필수 수행문장(close등)
@Ignore
- 테스트를 수행하지 않는다 (@Test @Ignore로 사용)
public class Example {
File output;
@Before public void createOutputFile() {
output= new File(...);
}
@Test public void something() {
...
}
@After public void deleteOutputFile() {
output.delete();
}
}
@Before public void createOutputFile() {
output= new File(...);
}
@Test public void something() {
...
}
@After public void deleteOutputFile() {
output.delete();
}
}
2-1 프로젝트선택후 우클릭 > Build Path > Configure Build Path
2-2 Add Library > JUnit > Next
2-3 JUnit4 > Finish
추가된거 확인후 Apply
ex : JUnit으로 테스트하면 정상값이나온경우 초록색이 나타남
Spring Test( Core 는 JUnit)
1.Maven을 통한 download (https://mvnrepository.com/artifact/org.springframework/spring-test/4.2.9.RELEASE)
--> pom.xml 에 복사하여 down받는다.
2.Test class 선언부
@Runwith(SpringJunit4ClassRunner.class)
@ContextConfiguration("config/Beans.xml"); //xml 경로지정
@Autowired
private ApplicationContext // 굳이 getBean을 여러번 하지 않아도 된다.
--> 의존관계가 있는 객체를 자동으로 주.입(Injection)해주는 어노태이션
@Qualifier("bean id "); // 동일한 클래스의 bean이 여러개있는경우, bean id를 지정해주는 방식(범위를 한정시킴)
@Component : bean을 등록할때 사용 (컴포넌트는 대표이고, 특화된것을 사용하고싶으면 repository,service,controller
- @Repository : DAO 객체
- @Service : 서비스 객체
- @Controller : 웹화면쪽 연결 Controller 객체 / web tear(톰캣상에서 실행)
@Resource : 의존관계
DI 구현방식
ㅇ XML 사용하는 방식(bean등록 dependency 설정)
<bean id ="helloC" class="xxx.Hello">
<property name="name" value="jeogwon"></property>
<property name="printer" ref="stringPrinter"></property>
</bean>
<bean id="stringPrinter" class="xxx.StringPrint">
</bean>
ㅇ Annotation을 사용하는 방식 (spring 2.5버전이후 생성됨)
@Component
public class Hello{
@Value("jeongwon")
String name;
@Autowired
@Quilifier("stringPrinter")
Printer printer;
}
@Component("stringPrinter")
public class StringPrinter implements Printer{
}
어노태이션 : xml설정 덜하고, 소스에 직접박혀있어서 사용하기에는 편하지만, bean은 그래프로 되어있어서 한눈에 파악하기 쉬움
개발 타이밍 : 어노태이션 / 운영 : xml(빈 그래프)
bean.xml
<!-- properties 파일의 정보를 설정 -->
<context:property-placeholder location="classpath:config/values.properties"/>
WAS : EJB Container + Web Container (ex : 웹로직,제우스..)
ORM(Object Relational Mapping) Framework
- MyBatis(iBatis)
- Hibernate
- JPA(Java Persistance API)
JDBC->Spring JDBC -> MyBatis
DBCP(DataBase Connection Pooling)
-> 여러개 connection을 만든후, 재사용하여 사용 / 웹환경 필수 (ex :
Apach DBCP common API 2.2.1)
pom.xml
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.1.1</version>
</dependency>
SDDS(SimpleDriverDataSource)
Beans.xml
<!-- DataSource 설정 -->
<bean id='dataSource' class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="${db.driverClass}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
ojdbc
<!-- JDBC 추가 -->
<dependency>
<groupId>ojdbc</groupId>
<artifactId>ojdbc</artifactId>
<version>6</version>
<scope>system</scope>
<systemPath>${basedir}/lib/ojdbc6.jar</systemPath>
</dependency>
Maven 생성확인
<참고>
-
Apach DBCP common API 2.2.1 : https://commons.apache.org/proper/commons-dbcp/apidocs/
'IT > SPRING' 카테고리의 다른 글
[파일] 스프링 정리 (0) | 2017.04.29 |
---|---|
[링크] Spring 관련 API (0) | 2017.04.29 |
[교육] Spring Framework 교육 (4일차) (0) | 2017.04.29 |
[교육] Spring Framework 교육 (3일차) (0) | 2017.04.29 |
[교육] Spring Framework 교육 (1일차) (0) | 2017.04.29 |