(简单实用的) Junit 单元测试依赖@Test注解

2022-11-20 11:00:31

基本使用步骤:(默认使用maven创建项目)

  1. pom.xml中引入依赖:
<!--单元测试的依赖--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency>
  1. 示例编写一个java程序:
publicclassTest{publicvoidtest(){System.out.println("JUnit单元测试");}}
  1. 给方法加注解:@Test
publicclassTest{@Testpublicvoidtest(){System.out.println("JUnit单元测试");}}
  1. 点击测试运行:
    在这里插入图片描述
    查看运行结果:
    在这里插入图片描述

依赖特点:

  • 简单使用,方法上加上注解@Test即可使用
  • 不需要使用main方法就能执行方法。

缺点:

  • 只适用于方法测试。

So:

  • 以后运行方法,可以直接使用junit依赖的@Test注解进行。

The End!!创作不易,欢迎点赞/评论!!欢迎关注个人公众号

  • 作者:Carson's blog
  • 原文链接:https://blog.csdn.net/weixin_46350177/article/details/119943673
    更新时间:2022-11-20 11:00:31