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

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è)
国产一区二区三区免费有码视频 | 亚洲黄色手机在线网站| 亚洲成人av毛片在线观看| 在线国产一区二区不卡| 日韩在线视频观看一区二区三区| 日韩精品专区在线影院重磅| 国产片中文字幕在线观看| 国产精品传媒成人免费| 麻豆精品人妻中文在线| 日韩人妻高清精品专区| 麻豆国产传媒片在线看| 蜜臀av成人精品蜜臀av| 国产激情视频在线观看你懂的| 亚洲一区二区视频免费看| 清纯少妇激情四射网站| 日韩一级免费高清黄片| 国产高清av免费观看| 91精品国产色综合久久不| 青青草原在线影视一区| 末满18周岁禁止观看| 日本道欧美一区二区aaaa| 日本的黄色录像一级带| 九色91成人在线视频| 日本特黄特色大片免费| 亚洲成熟中老妇女视频| av天堂男人站在线观看| 亚洲成av人在线观看福利| 91九色国产成人久久精品| 成人免费激情在线观看| 日韩一区二区三区成人| 凹凸国产精品熟女视频| 高清国产国产精品三级国产av| 国产精品一区二区剧情熟女| 麻豆看片高清在线播放| 婷婷激情亚洲综合综合久久| 人妻中文字幕日韩av| av岛国不卡一区二区在线观看| 亚洲国产第一av导航| 视频一区二区日韩不卡| 2021亚洲精品午夜精品国产| 农村人妻一区二区三区视频 |