scalatest-csv-table

A scalatest helper for table driven testing with csv

License

License

Categories

Categories

Scala Languages CSV Data Data Formats
GroupId

GroupId

io.github.akiomik
ArtifactId

ArtifactId

scalatest-csv-table_2.11
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

scalatest-csv-table
A scalatest helper for table driven testing with csv
Project URL

Project URL

https://github.com/akiomik/scalatest-csv-table
Project Organization

Project Organization

io.github.akiomik
Source Code Management

Source Code Management

https://github.com/akiomik/scalatest-csv-table

Download scalatest-csv-table_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.akiomik/scalatest-csv-table_2.11/ -->
<dependency>
    <groupId>io.github.akiomik</groupId>
    <artifactId>scalatest-csv-table_2.11</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.akiomik/scalatest-csv-table_2.11/
implementation 'io.github.akiomik:scalatest-csv-table_2.11:1.0.2'
// https://jarcasting.com/artifacts/io.github.akiomik/scalatest-csv-table_2.11/
implementation ("io.github.akiomik:scalatest-csv-table_2.11:1.0.2")
'io.github.akiomik:scalatest-csv-table_2.11:jar:1.0.2'
<dependency org="io.github.akiomik" name="scalatest-csv-table_2.11" rev="1.0.2">
  <artifact name="scalatest-csv-table_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.akiomik', module='scalatest-csv-table_2.11', version='1.0.2')
)
libraryDependencies += "io.github.akiomik" % "scalatest-csv-table_2.11" % "1.0.2"
[io.github.akiomik/scalatest-csv-table_2.11 "1.0.2"]

Dependencies

compile (4)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
org.scalatest : scalatest_2.11 jar 3.0.9
com.nrinaudo : kantan.csv_2.11 jar 0.5.1
com.nrinaudo : kantan.csv-generic_2.11 jar 0.5.1

Project Modules

There are no modules declared in this project.

scalatest-csv-table

Latest version Scala CI Test Coverage

A scalatest helper for loading csv files as Table.

Getting started

scalatest-csv-table is currently available for Scala 2.12 and 2.13.

Add the following lines to your build.sbt.

libraryDependencies += "io.github.akiomik" %% "scalatest-csv-table" % "1.2.1" % 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.1 3.2.x 2.12.x/2.13.x

Basic usage

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""".stripMargin

    val 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.

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""".stripMargin

    val tests = CsvTable.fromString[Foo](csv)
    forAll (tests) { (foo: Foo) => 
      // ...
    }
  }
}

Versions

Version
1.0.2
1.0.1