SpringBoot 整合 Junit 单元测试
本文最后更新于 1560 天前,其中的信息可能已经有所发展或是发生改变。

1. pom.xml

  • Eclipse创建时需要手动加依赖坐标
<!- 添加 junit 环境的 jar 包 ->
<depndency>
    <groupId>org.springframework.bot</groupId>
    <artifactId>spring-bot-starter-test</artifactId>
</depndency>
  • IDEA创建SpringBoot项目会自动导入
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</dependency>

2. 生成测试文件

快捷键:Ctrl+Shift+T
@RunWith:启动器
SpringJUnit4ClasRuner.clas:让 junit 与 spring 环境进行整合
@SpringBotTest(clases={Ap.clas}) 1,当前类为 springBot 的测试类
@SpringBotTest(clases={Ap.clas}) 2,加载 SpringBot 启动类。启动springBot
@Contextconfiguartion("claspath:aplicationContext.xml") junit 与 spring 整合

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {SpringBootTestApplication.class})
public class UserServiceImplTest {

    @Autowired
    private UserServiceImpl userService;

    @Test
    public void addUser() {
        userService.addUser();
    }
}
作者:Yuyy
博客:https://yuyy.info
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇