scalaTest的使用

修改pom.xml,添加以下内容

<!--依赖-->

<dependency>

  <groupId>org.scalatest</groupId>

  <artifactId>scalatest_2.11</artifactId>

  <version>3.0.0</version>

  <scope>test</scope>

</dependency>

<!--插件-->

<plugin>

    <groupId>org.scalatest</groupId>

    <artifactId>scalatest-maven-plugin</artifactId>

    <version>1.0</version>

    <configuration>

        <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>

        <junitxml>.</junitxml>

        <filereports>WDF TestSuite.txt</filereports>

    </configuration>

    <executions>

        <execution>

            <id>test</id>

            <goals>

                <goal>test</goal>

            </goals>

        </execution>

    </executions>

</plugin>

<!--测试代码和文件-->

<testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>

一个简单的例子

import org.scalatest.FunSuite

class SetFuncSuite extends FunSuite {

  //差集

  test("Test difference") {

    val a = Set("a", "b", "a", "c")

    val b = Set("b", "d")

    assert(a -- b === Set("a", "c"))

  }

  //交集

  test("Test intersection") {

    val a = Set("a", "b", "a", "c")

    val b = Set("b", "d")

    assert(a.intersect(b) === Set("b"))

  }

  //并集

  test("Test union") {

    val a = Set("a", "b", "a", "c")

    val b = Set("b", "d")

    assert(a ++ b === Set("a", "b", "c", "d"))

  }

}

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容