Scala系列文章二:测试工具与覆盖率工具的使用

本文档介绍了如何使用ScalaTest编写测试用例,通过Sbt运行所有测试用例,获取覆盖率报告,以及如何指定运行特定的测试文件。推荐使用ScalaTest3.0.3,并详细说明了各个步骤的命令行操作。覆盖报告显示在`target/scala-<scala-version>/scoverage-report`目录下,包括HTML和XML格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sbt Test

1 Write a test using ScalaTest

ScalaTest is recommened by the official team. In my blog, I use ScalaTest 3.0.3
Please refer to the official Scala Doc to know how to use ScalaTest to write your test cases.

2 Run all test cases

# run the command in your IDE below
sbt clean coverage test

# the above is the most recommended way to run
# if you just want to get the test results, use this command is faster
sbt test

3 Get coverage report

I highly recommend this coverage tool, please refer to sbt-coverage to install it.

# after finishing step 1 (with coverage), we can get coverage report running the command below
sbt coverageReport

# Coverage reports will be in your `target/scala-<scala-version>/scoverage-report` # directory. There are HTML and XML reports. 
# The XML is useful if you need to
# programatically use the results, or if you're writing a tool.

4 Run specific test file

# you can run specific test file as follows:
sbt "testOnly yourPakageName.yourClassName"

# eg: sbt "testOnly org.apache.spark.dolphin.configuration.defaultConfigTest"

All concluded by Ruifeng Tan

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值