美文网首页Maven
Maven入坑(三) 测试 JUnit

Maven入坑(三) 测试 JUnit

作者: 湛青 | 来源:发表于2016-11-08 21:43 被阅读7次

    Maven 专题

    根据Hello world 创建出来项目以后, 我们继续来为项目增加单元测试功能.

    安装依赖

    pom.xml中新增

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    

    编写测试代码

    1. 创建包目录 mkdir -p src/test/java/com/example

    2. 创建文件 HelloWorldTest.java
      package com.example;

      import org.junit.Assert;
      import org.junit.Test;
      
      /**
       * Created by zy on 2016/11/8.
       */
      public class HelloWorldTest {
      
          @Test
          public void sayHelloTest(){
              HelloWorld helloWorld = new HelloWorld();
              String result = helloWorld.sayHello();
              Assert.assertEquals("Hello world",result);
          }
      }
      

    执行测试

    mvn test

    相关文章

      网友评论

        本文标题:Maven入坑(三) 测试 JUnit

        本文链接:https://www.haomeiwen.com/subject/utcauttx.html