develog

[JUnit] JUnit Transaction Rollback 본문

Dev/junit

[JUnit] JUnit Transaction Rollback

냐옴 2015. 5. 6. 11:39


import java.sql.Connection;

import java.sql.PreparedStatement;


import javax.sql.DataSource;


import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.jdbc.datasource.DataSourceUtils;

import org.springframework.test.annotation.Rollback;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.transaction.annotation.Transactional;


import common.ExtSpringJUnit4ClassRunner;


@RunWith(ExtSpringJUnit4ClassRunner.class)

@ContextConfiguration(locations = { "classpath:spring-application.xml" })

public class Test_트랜잭션 {

@Qualifier("dataSource")

@Autowired

private DataSource dataSource;

@Test

@Transactional

// @Rollback(false)

public void tranTest() throws Exception {

Connection conn = DataSourceUtils.getConnection(dataSource);

String sql = "INSERT INTO AATEST (SEQ, TITLE, REG_TS) VALUES (1, 2, SYSTIMESTAMP)";

PreparedStatement pstmt = conn.prepareStatement(sql);

pstmt.executeUpdate();

}

    

}


'Dev > junit' 카테고리의 다른 글

[junit] spring junit 설정2  (0) 2019.08.02
[junit] spring junit 설정1  (0) 2019.08.02
JUnit 에서 ApplicationContext 접근  (0) 2013.12.11
[junit] ExtSpringJUnit4ClassRunner  (0) 2013.12.09
JUnit 버전 확인  (0) 2013.12.09
Comments