■ はじめに
https://dk521123.hatenablog.com/entry/2023/03/27/001306
の続き。 今回は、ScalaTest での Hello worldと基本的な事項をまとめておく。
目次
【1】Hello World 1)サンプル 【2】テスト実行方法 1)sbt test 2)sbt testOnly
【1】Hello World
* 自分の簡単なコードでテストしてみる
1)サンプル
HelloWorld.scala
package com.example object HelloWorld { def sayHello(name: String): String = { require(name.nonEmpty) s"Hello, ${name}." } }
HelloWorldTest.scala
package com.example import org.scalatest.funspec.AnyFunSpec class HelloWorldTest extends AnyFunSpec { describe("Hello World Test") { describe("Normal") { it("Set name=Mike") { val result = HelloWorld.sayHello("Mike") assert(result == "Hello, Mike!!") } } describe("Abnormal") { it("should produce IllegalArgumentException when name is empty") { assertThrows[IllegalArgumentException] { HelloWorld.sayHello("") } } } } }
【2】テスト実行方法
1)sbt test
* sbt test でテスト全体を実行
テスト実行
sbt test [info] HelloWorldTest: [info] Hello World Test [info] Normal [info] - should produce NoSuchElementException when head is invoked [info] - Set name=Mike [info] Abnormal [info] - should produce IllegalArgumentException when name is empty [info] Run completed in 740 milliseconds. [info] Total number of tests run: 2 [info] Suites: completed 2, aborted 0 [info] Tests: succeeded 2, failed 0, canceled 0, ignored 0, pending 0 [info] All tests passed.
2)sbt testOnly
* sbt testOnly <対象テスト>で、個別実行
テスト実行
sbt testOnly HelloWorldTest
参考文献
https://qiita.com/suin/items/0294a53d6babd69f29a9
関連記事
Scala ~ テスティングフレームワーク ~
https://dk521123.hatenablog.com/entry/2024/06/07/183708
ScalaTest ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2023/03/27/001306
ScalaTest ~ あれこれ編 ~
https://dk521123.hatenablog.com/entry/2024/06/11/232020
ScalaTest ~ with ScalaCheck ~
https://dk521123.hatenablog.com/entry/2023/03/29/000014
ScalaTest ~ with Mockito ~
https://dk521123.hatenablog.com/entry/2023/03/31/002830
ScalaTest ~ with Coverage ~
https://dk521123.hatenablog.com/entry/2023/08/07/222945
specs2 ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2024/06/08/122708
specs2 ~ 基本編 ~
https://dk521123.hatenablog.com/entry/2024/06/09/221005
Scala ~ 環境構築編 ~
https://dk521123.hatenablog.com/entry/2023/03/10/193805
Scala ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2023/03/12/184331
Scala ~ 基本編 / 繰り返し ~
https://dk521123.hatenablog.com/entry/2023/01/24/000000
Scala ~ 基本編 / Option型 ~
https://dk521123.hatenablog.com/entry/2023/03/09/000000
Scala ~ 基本編 / メソッド ~
https://dk521123.hatenablog.com/entry/2023/03/03/000000
Scala ~ 基本編 / クラス ~
https://dk521123.hatenablog.com/entry/2023/03/14/000857
Scala ~ 基本編 / コレクション ~
https://dk521123.hatenablog.com/entry/2023/03/13/000345
Scala ~ 基本編 / 日付・日時 ~
https://dk521123.hatenablog.com/entry/2023/03/08/000000
Scala ~ 基本編 / 正規表現 ~
https://dk521123.hatenablog.com/entry/2023/03/18/034704
Scala ~ 基本編 / ジェネリック
https://dk521123.hatenablog.com/entry/2023/03/21/003817
Scala ~ Enum ~
https://dk521123.hatenablog.com/entry/2023/01/05/000000
Scala ~ ファイル名・パスの扱い ~
https://dk521123.hatenablog.com/entry/2023/03/11/000000
Scala ~ ファイルハンドリング ~
https://dk521123.hatenablog.com/entry/2023/01/03/000000
Scala ~ YAML ~
https://dk521123.hatenablog.com/entry/2023/03/16/012034
Scala ~ JDBC / DB接続 ~
https://dk521123.hatenablog.com/entry/2023/03/26/000950
Scala ~ AWS SDK ~
https://dk521123.hatenablog.com/entry/2023/03/24/211033
SBT ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2023/03/22/000000
SBT ~ 基本編 / build.sbt ~
https://dk521123.hatenablog.com/entry/2023/01/27/000000
SBT ~ 基本編 / sbtコマンド ~
https://dk521123.hatenablog.com/entry/2023/01/26/000000
SBT ~ sbtプラグイン ~
https://dk521123.hatenablog.com/entry/2023/01/25/000000
JavaでEmail ~ JavaMail / Text ~
https://dk521123.hatenablog.com/entry/2016/07/16/222422
JavaでEmail ~ JavaMail / 添付ファイル ~
https://dk521123.hatenablog.com/entry/2016/07/17/023459
JavaでEmail ~ SMTP認証 ~
https://dk521123.hatenablog.com/entry/2016/11/07/215251
JavaでEmail ~ SMTP認証 / DIGEST-MD5 ~
https://dk521123.hatenablog.com/entry/2016/12/07/222229
JavaでEmail ~ JavaMail / TLS ~
https://dk521123.hatenablog.com/entry/2017/05/03/163219
JavaでEmail ~ JavaMail / Return-Path・Errors-To ~
https://dk521123.hatenablog.com/entry/2017/05/07/000344
Amazon SES ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2017/04/28/234103
Amazon S3 ~ Boto3編 ~
https://dk521123.hatenablog.com/entry/2019/10/21/230004
Amazon S3 ~ Boto3でファイル存在チェック ~
https://dk521123.hatenablog.com/entry/2022/02/26/182526
AWS Glue ~ Scalaでの実装 ~
https://dk521123.hatenablog.com/entry/2023/03/17/000000
AWS Glue ~ ローカル環境を作成する / Glue v3.0版 ~
https://dk521123.hatenablog.com/entry/2022/01/31/165650
LocalStack ~ ローカルで疑似AWSを作成する ~
https://dk521123.hatenablog.com/entry/2019/12/14/010524
LocalStack ~ ローカルで疑似Lambda/S3/DynamoDBを作成する ~
https://dk521123.hatenablog.com/entry/2019/12/16/231149
SparkからSnowflakeへの接続について考える
https://dk521123.hatenablog.com/entry/2023/03/19/013833
Mockito ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2014/07/18/233904
Mockito ~ 基本編 ~
https://dk521123.hatenablog.com/entry/2014/07/19/121409