2025年scala编写第一个测试用例使用testng

scala编写第一个测试用例使用testngscala 编写测试用例 1 软件都需要单元测试 需要编写一个测试用例验证程序是否正确 2 源代码 需要测试函数平方是否正确 举例说明 2 1 被测试代码为 object HelloKeny extends App def main args Array String println Hello

大家好,我是讯享网,很高兴认识大家。

scala编写测试用例

1.软件都需要单元测试,需要编写一个测试用例验证程序是否正确

2.源代码

需要测试函数平方是否正确,举例说明

2.1被测试代码为:

  def square(x: Int) = x * x

}

2.2测试用例为:

import org.testng.annotations._ import org.testng.Assert import org.scalatest.testng.TestNGSuite import java.lang.Boolean class SquareHelloKenyTest extends TestNGSuite { @Test def testquare{assert(HelloKeny.square(10) === 100) } } 验证HelloKeny.square(10)===1000,如果是正确的,返回0

讯享网

2.3build.sbt需要增加一个类支持

讯享网libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test" libraryDependencies += "org.testng" % "testng" % "5.7" classifier "jdk15" 

 

3.编译

sbt test 编译和测试用例运行成功!

[info] Loading global plugins from /Users/keny/.sbt/1.0/plugins
[info] Loading project definition from /Users/keny/PythonProjects/sbtDemo/project
[info] Loading settings for project sbtdemo from build.sbt ...
[info] Set current project to sbtDemo (in build file:/Users/keny/PythonProjects/sbtDemo/)
[info] Compiling 1 Scala source to /Users/keny/PythonProjects/sbtDemo/target/scala-2.11/test-classes ...
[warn] there was one deprecation warning; re-run with -deprecation for details
[warn] one warning found
[warn] Getting the hostname AppledeMacBook-Pro.local was slow (5006. ms). This is likely because the computer's hostname is not set. You can set the hostname with the command: scutil --set HostName $(scutil --get LocalHostName).
[Parser] Running:
  Command line suite


讯享网


===============================================
Command line suiteKenyTest 0s
Total tests run: 1, Failures: 0, Skips: 0
===============================================

[info] SquareHelloKenyTest:
[info] - testquare
[info] Run completed in 405 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 7 s, completed 2020-4-2 10:45:55

 

用最新版本编译完成OK

[info] Compiling 2 Scala sources to /Users/keny/PythonProjects/sbtDemo/target/scala-2.13/classes ...
[info] Compiling 1 Scala source to /Users/keny/PythonProjects/sbtDemo/target/scala-2.13/test-classes ...
[warn] there was one deprecation warning
[warn] there was one deprecation warning (since 2.13.0)
[warn] there were two deprecation warnings in total; re-run with -deprecation for details
[warn] three warnings found
[Parser] Running:
  Command line suite


===============================================
Command line suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
  | => SquareHelloKenyTest 0s
[info] SquareHelloKenyTest:
[info] - testquare
[info] Run completed in 500 milliseconds.
[info] Total number of tests run: 1
[info] Suites: completed 1, aborted 0
[info] Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
[info] All tests passed.
[success] Total time: 459 s (07:39), completed 2020-4-2 11:00:27
 

 

 

 

 

 

小讯
上一篇 2025-01-28 13:46
下一篇 2025-02-10 14:54

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/70660.html