1.框架结构
spring +spring mvc+mybatis idea
2.例子如下(仅供参考使用):
import com.raipeng.sales.entity.Sales;
import com.raipeng.sales.front.repository.SalesRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by 111 on 2015/11/28.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
@Transactional
@TransactionConfiguration(transactionManager = "transactionManager" ,defaultRollback = true)
public class SalesDaoTest {
@Autowired
public SalesRepository salesRepository;
@Test
public void testFindList(){
List<Sales> salesList = salesRepository.findSalesListBySalesId(1l);
System.out.println(salesList.size());
}
@Test
@Rollback(value = false)
public void testUpdateSales(){
Sales sales = salesRepository.findSalesBySalesId(1l);
sales.setCashStatus(1);
sales.setAmount("9999.99");
int num = salesRepository.updateSalesBySales(sales);
System.out.println(num+"___________");
}
}
3.spring整合junit需要注意的是:
spring只对junit4.5以上版本支持,否则@RunWith这个注解是无法引用的;