Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akiomik/scalatest-csv-table
A scalatest helper for table driven testing with csv.
https://github.com/akiomik/scalatest-csv-table
csv property-based-testing scalatest table-driven-testing
Last synced: 29 days ago
JSON representation
A scalatest helper for table driven testing with csv.
- Host: GitHub
- URL: https://github.com/akiomik/scalatest-csv-table
- Owner: akiomik
- License: apache-2.0
- Created: 2019-05-30T17:40:44.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-06-19T23:19:16.000Z (over 1 year ago)
- Last Synced: 2024-05-01T21:48:32.680Z (9 months ago)
- Topics: csv, property-based-testing, scalatest, table-driven-testing
- Language: Scala
- Homepage:
- Size: 156 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
scalatest-csv-table
===================
[![Latest version](https://index.scala-lang.org/akiomik/scalatest-csv-table/scalatest-csv-table/latest.svg?color=blue&style=flat)](https://index.scala-lang.org/akiomik/scalatest-csv-table/scalatest-csv-table)
[![Scala CI](https://github.com/akiomik/scalatest-csv-table/workflows/Scala%20CI/badge.svg)](https://github.com/akiomik/scalatest-csv-table/actions?query=workflow%3A%22Scala+CI%22)
[![Test Coverage](https://api.codeclimate.com/v1/badges/9f38579ddc03f2c6e5e8/test_coverage)](https://codeclimate.com/github/akiomik/scalatest-csv-table/test_coverage)A [scalatest](http://www.scalatest.org/) helper for loading csv files as [`Table`](http://www.scalatest.org/user_guide/table_driven_property_checks).
## Getting started
scalatest-csv-table is currently available for Scala 2.12 and 2.13.
Add the following lines to your `build.sbt`.
```scala
libraryDependencies += "io.github.akiomik" %% "scalatest-csv-table" % "1.2.2" % Test
```NOTE: The groupid has been changed from `com.github.akiomik` to `io.github.akiomik` because the maven repository has been changed from bintray to sonatype.
## All releases
scalatest-csv-table supports some different versions of scalatest.
| scalatest-csv-table version | scalatest version | scala version |
| --------------------------- | ----------------- | ------------- |
| 1.0.2 | 3.0.x | 2.11.x/2.12.x |
| 1.1.0 | 3.1.x | 2.12.x/2.13.x |
| 1.2.2 | 3.2.x | 2.12.x/2.13.x |## Basic usage
```scala
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.prop.TableDrivenPropertyChecks._import com.github.akiomik.scalatest._
class FizzBuzzSpec extends AnyFlatSpec {
"A FizzBuzz" should "pass tests from a string" in {
val csv =
"""n,expected
|1,1
|2,2
|3,Fizz
|4,4
|5,Buzz""".stripMarginval tests = CsvTable.fromString[Int, String](csv)
forAll (tests) { (n: Int, expected: String) =>
assert(FizzBuzz(n) == expected)
}
}"A FizzBuzz" should "pass tests from a file" in {
val tests = CsvTable.fromFile[Int, String]("src/test/resources/fizzbuzz.csv")
forAll (tests) { (n: Int, expected: String) =>
assert(FizzBuzz(n) == expected)
}
}"A FizzBuzz" should "pass tests from a resource file" in {
val tests = CsvTable.fromResource[Int, String]("fizzbuzz.csv") // from `src/test/resouces`
forAll (tests) { (n: Int, expected: String) =>
assert(FizzBuzz(n) == expected)
}
}
}
```## Using case classes
Use [`RowDecoder` of kantan.csv](https://nrinaudo.github.io/kantan.csv/rows_as_case_classes.html).
```scala
import com.github.akiomik.scalatest._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.prop.TableDrivenPropertyChecks._
import kantan.csv._case class Foo(i: Int, s: String, b: Boolean)
class FooSpec extends AnyFlatSpec {
implicit val decoder = RowDecoder.decoder(0, 1, 2)(Foo.apply _) //"A Foo" should "pass tests from a string" in {
val csv =
"""i,s,b
|1,a,true
|2,b,true
|3,f,false
|4,e,false
|5,e,true""".stripMarginval tests = CsvTable.fromString[Foo](csv)
forAll (tests) { (foo: Foo) =>
// ...
}
}
}
```