zoukankan      html  css  js  c++  java
  • jUnit

    1. pom.xml

    <!--  spring3.2之前需要加下面的依赖  -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
    </dependency>
    <dependency>
        <groupId>asm</groupId>
        <artifactId>asm-all</artifactId>
        <version>2.1</version>
    </dependency>

    2. application.xml 中配置 transactionManager

    <!-- 配置事务管理器 -->
    <!-- 或者 org.springframework.jdbc.datasource.DataSourceTransactionManager -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    3. AbstractTestCast.java

     1 @RunWith(SpringJUnit4ClassRunner.class)
     2 @ContextConfiguration("/applicationContext.xml")
     3 @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
     4 @Transactional
     5 public class AbstractTestCase {
     6     protected static final Logger log = LoggerFactory.getLogger(AbstractTestCase.class);
     7     
     8     @Before
     9     public void init() {
    10         // ...
    11     }
    12     
    13     public static void main(String[] args) {
    14         
    15     }
    16     
    17 }

    4. XXXTest.java

     1 import org.junit.After;
     2 import org.junit.Before;
     3 import org.junit.Test;
     4 import static org.junit.Assert.*;
     5 
     6 public class ZXTest extends AbstractTestCase {
     7     
     8     @Before
     9     public void login() {
    10         assertNotNull("");
    11     }
    12     
    13     @After
    14     public void logout() {
    15         
    16     }
    17     
    18     @Test
    19     public void testChangePassword() {
    20         
    21     }
    22 
    23 }

    别忘了这一行 : import static org.junit.Assert.*;

  • 相关阅读:
    Mac php使用gd库出错 Call to undefined function imagettftext()
    centos 使用 locate
    Mac HomeBrew 安装 mysql
    zsh 命令提示符 PROMPT
    新的开始
    Java 面试题分析
    Java NIO Show All Files
    正确使用 Volatile 变量
    面试题整理 2017
    有10阶梯, 每次走1,2 or 3 阶,有多少种方式???
  • 原文地址:https://www.cnblogs.com/ykt8465279130/p/3459499.html
Copyright © 2011-2022 走看看