欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

JavaConfig下的SpringTest幾種方式實(shí)例詳解

Java Config 下的Spring Test方式

成都創(chuàng)新互聯(lián)公司專(zhuān)業(yè)為企業(yè)提供大安市網(wǎng)站建設(shè)、大安市做網(wǎng)站、大安市網(wǎng)站設(shè)計(jì)、大安市網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、大安市企業(yè)網(wǎng)站模板建站服務(wù),十余年大安市做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

用了三種方式:

1.純手動(dòng)取bean:

package com.wang.test;

import com.marsmother.commission.core.config.MapperConfig;
import com.marsmother.commission.core.config.PropertyConfig;
import com.marsmother.commission.core.config.ServiceConfig;
import com.marsmother.commission.core.dto.GeneralResponseData;
import com.marsmother.commission.core.service.UserService;
import com.marsmother.commission.site.config.SecurityConfig;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Created by Wanglei on 15/10/29.
 */
public class CustomeTest {

  private static AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();

  @Before
  public void tearUp(){
    context.register(PropertyConfig.class);
    context.register(ServiceConfig.class);
    context.register(SecurityConfig.class);
    context.register(MapperConfig.class);
    context.refresh();
  }

  @Test
  public void testUser(){
    UserService userService = context.getBean(UserService.class);
    Long userId = 3L;
    GeneralResponseData data = userService.addUserRelation(userId);
    System.out.println(data.getMsg());
  }
}

2.采用spring-test

package com.wang.test;

import com.marsmother.commission.core.config.MapperConfig;
import com.marsmother.commission.core.config.PropertyConfig;
import com.marsmother.commission.core.config.ServiceConfig;
import com.marsmother.commission.core.dto.GeneralResponseData;
import com.marsmother.commission.core.service.UserService;
import com.marsmother.commission.site.config.SecurityConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * Created by Wanglei on 15/10/29.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {PropertyConfig.class, ServiceConfig.class, SecurityConfig.class, MapperConfig.class})
public class SpringTest {

  @Autowired
  private UserService userService;

  @Test
  public void testUser(){
    GeneralResponseData data= userService.addUserRelation(3L);
    System.out.println(data.getMsg());
  }

}

3.采用Mockito

需要引入相應(yīng)包:

<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-all</artifactId>
  <version>1.9.5</version>
  <scope>test</scope>
</dependency>
package com.wang.test;

import com.marsmother.commission.core.dto.GeneralResponseData;
import com.marsmother.commission.core.presistence.FollowNumberMapper;
import com.marsmother.commission.core.presistence.UserMapper;
import com.marsmother.commission.core.presistence.UserRelationMapper;
import com.marsmother.commission.core.service.UserService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

/**
 * Created by Wanglei on 15/10/29.
 */
public class TestUserService {

  @InjectMocks
  private UserService userService;

  @Mock
  private FollowNumberMapper followNumberMapper;
  @Mock
  private UserMapper userMapper;
  @Mock
  private UserRelationMapper userRelationMapper;

  @Before
  public void init(){
    MockitoAnnotations.initMocks(this);
  }

  @Test
  public void testUser(){
    Long userId = 3L;
    GeneralResponseData result = userService.addUserRelation(userId);
    System.out.println(result.getMsg());
  }

}

這里@Mock的話,并不會(huì)真正的去執(zhí)行數(shù)據(jù)庫(kù)的操作。

還有一種用法是@Spy,暫時(shí)不了解具體使用方式,待研究。

相比之下,還是spring-test標(biāo)準(zhǔn)一些。

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

新聞標(biāo)題:JavaConfig下的SpringTest幾種方式實(shí)例詳解
文章路徑:http://www.aaarwkj.com/article32/jpoosc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營(yíng)銷(xiāo)推廣、網(wǎng)站營(yíng)銷(xiāo)品牌網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、ChatGPT、軟件開(kāi)發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

營(yíng)銷(xiāo)型網(wǎng)站建設(shè)
久久精品视频视频视频| 九九热在线免费观看精品视频| 国产精品欧美日韩中文| 中文字幕日本精品人妻在线| 日韩av网址在线免费观看| 国内精品免费视频不卡| 日韩高清精品视频在线| 国产69精品久久久久久人| 国产91高清视频在线观看| 免费国产黄片在线播放| 韩国三级伦理中文字幕| 亚洲国产a级一区二区| 日韩精品女性三级视频| 麻豆视频在线观看传媒| 高清中文一区二区三区| 97视频精品在线播放| 宅男午夜一区二区三区| 好吊视频在线免费观看| 一二三日韩电影在线观看| 色哟哟在线观看精品一区| 欧美欧美一区二区三区| 国产成人亚洲综合色影视| 啊啊舒服爽用力爱我视频| 国产精品一区二区一牛影视| 在线国产偷拍自拍视频| 日本电影在线看一区二区| 欧美精品国产欧美精品国产| 中文字幕在线看二区不卡| 精品亚洲午夜久久久久| 国产一区二区不卡在线播放| 国产老妇伦国产熟女高清| 国产黄色大片一级久久| 我要看黄色一级性生活片| 91精品亚洲内射孕妇| 午夜精品一区二区亚洲| 日韩不伦高清一区二区三区| 五月天丁香婷婷狠狠狠| 国产高清大片一级黄色| 人妻人人澡人人添人人爽桃色| 国产精品乱码精品久久久| 抱着操才爽的免费视频观看|