乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      SSM項(xiàng)目各層單元測試

       Architect_home 2019-04-03

      數(shù)據(jù)層的測試

      數(shù)據(jù)主要使用Mybatis,因此注入的時(shí)候也只需要引入Mybatis相關(guān)的配置

      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration({ "classpath:spring/spring-dao.xml" })
      public class SeckillDaoTest {
      
      	// 注入Dao實(shí)現(xiàn)類依賴
      	@Resource
      	private SeckillDao seckillDao;
      
      	@Test
      	public void testReduceNumber() {
      		long seckillId=1000;
              Date date=new Date();
              int updateCount=seckillDao.reduceNumber(seckillId,date);
              System.out.println(updateCount);
      	}
      }

      業(yè)務(wù)層測試

      業(yè)務(wù)層會(huì)涉及到多表的操作,因此需要引入事務(wù)。而為了方便重復(fù)測試,添加回滾功能。

      @RunWith(SpringJUnit4ClassRunner.class)
      @ContextConfiguration({ "classpath:spring/spring-dao.xml", "classpath:spring/spring-service.xml" })
      @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
      @Transactional
      public class SeckillServiceImplTest {
      
      	private final Logger logger = LoggerFactory.getLogger(this.getClass());
      
      	@Autowired
      	private SeckillService seckillService;
      
      	@Test
      	public void testGetSeckillList() {
      		List<Seckill> seckills = seckillService.getSeckillList();
      		System.out.println(seckills);
      	}
      }

      控制層測試

      控制層主要模擬用戶請求,這里設(shè)計(jì)到http請求,我們可以使用mock測試

      @WebAppConfiguration
      @ContextConfiguration({ "classpath:spring/spring-dao.xml", 
      	"classpath:spring/spring-service.xml",
      	"classpath:spring/spring-web.xml"})
      @RunWith(SpringJUnit4ClassRunner.class)
      @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
      @Transactional
      public class SeckillControllerTest  {
      
      	@Autowired
      	protected WebApplicationContext context;
      	
      	private MockMvc mockMvc;
      	private String listUrl = "/seckill/list";
      	private String detailUrl = "/seckill/{seckillId}/detail";
      	private String expserUrl = "/seckill/{seckillId}/exposer";
      	private long seckillId = 1000L;
      
      	@Before
      	public void setUp() {
      		this.mockMvc = webAppContextSetup(this.context).alwaysExpect(status().isOk()).alwaysDo(print()).build();
      	}
      
      	@Test
      	public void testList() throws Exception {
      		this.mockMvc.perform(get(listUrl)).andExpect(view().name("list"));
      	}
      
      	@Test
      	public void testExistDetail() throws Exception {
      		this.mockMvc.perform(get(detailUrl, seckillId)).andExpect(view().name("detail"))
      				.andExpect(model().attributeExists("seckill"));
      	}
      }

       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多