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

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://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è)
日本精品亚洲一区二区三区| 中文字幕精品免费日韩在线| 国产在线自拍一区二区| 一区二区欧美日韩91| 日日激情综合久久一区| 亚洲性感美女男人的天堂| 亚洲人成网站在线免费看| 亚洲综合色视频在线播放| 中文字幕成人资源网站| 特级特色生活片免费看| 国产亚洲精品视频免费| 99热国产这里只有精品| 国产成人大片一区二区三区| 国产精品久久一国产精品| 日本高清不卡在线观看| 精品久久中文字幕久久av| 国产午夜精品福利爽爽| 国产日韩精品在线视频| 国产精品日韩欧美亚洲| 禁止18岁以下观看的视频| 国产亚洲欧美日韩精品| 亚洲小视频免费在线观看| 久久青草精品欧美日韩精品| 男女午夜激情啪啪视频| 亭亭丁香激情五月涩久久| 中文字幕乱码亚洲影视| 91麻豆精品国产91久| 亚洲国产成人91精品| 91麻豆粉色视频在线| 亚洲免费av一区二区| 成年免费大片黄在线观看| 一级黄片视频免费下载| 国产毛片久久久久久国产| 日韩人妻精品久久免费| 国产成人综合亚洲乱淫.| 老汉av免费在线观看| 亚洲国产一区二区高清| 亚洲av成人精品日韩一区麻豆| 日韩成人精品一区欧美成人| 亚洲精品不卡在线观看| 免费福利激情在线播放|