Giter Site home page Giter Site logo

fireotter's Introduction

FireOtter

FireOtter is a simple CSV parsing library for building tests on human-readable, spreadsheet-based specifications.

Usage

Add FireOtter to the list of dependencies in build.sbt:

libraryDependencies += "com.versal" %% "fireotter" % "0.1.0" % "test"

How it works

FireOtter isn't much more than a CSV parser, but it provides a handy tool for test-driven development based on code-free test specifications written as human-readable spreadsheets.

First, establish a convention for how to express test specifications as spreadsheet rows. Then write the code necessary to bind them, given as a Traversable[Seq[String]], to your favorite test framework

Now you can run through the usual TDD loop:

  1. Describe a desired feature in terms of your expression convention
  2. Write the code needed to make the tests pass
  3. Repeat

Example

CSV test specifications:

testfunctioninputexpected output
1 + 1 = 2add"1, 1"2
2 - 1 = 1subtract"2, 1"1
2 * 3 = 6multiply"2, 3"6
6 / 3 = 2divide"6, 3"2

Code under test:

object Arithmetic {
  def add(x: Int, y: Int): Int = x + y
  def subtract(x: Int, y: Int): Int = x - y
  def multiply(x: Int, y: Int): Int = x * y
  def divide(x: Int, y: Int): Int = x / y
}

CSV specification parser and tester:

import com.versal.fireotter._

val specs: Traversable[Seq[String]] = csv(resource("arithmetic.csv"))

specs foreach { spec =>
  val inputs: Seq[Int] = spec(2).split(",").map(_.toInt)
  val output = spec(1) match {
    case "add"      => Arithmetic.add(inputs(0), inputs(1))
    case "subtract" => Arithmetic.subtract(inputs(0), inputs(1))
    case "multiply" => Arithmetic.multiply(inputs(0), inputs(1))
    case "divide"   => Arithmetic.divide(inputs(0), inputs(1))
  }
  val expectedOutput: Int = spec(3).toInt
  test(spec(0)) { assert(output === expectedOutput) }
}

Test output under ScalaTest:

> test
[info] ArithmeticTest:
[info] - 1 + 1 = 2
[info] - 2 - 1 = 1
[info] - 2 * 3 = 6
[info] - 6 / 3 = 2
[info] Passed: : Total 4, Failed 0, Errors 0, Passed 4, Skipped 0
[success] Total time: 0 s, completed Jun 5, 2013 1:01:05 PM

fireotter's People

Contributors

earldouglas avatar

Watchers

Marek Kolodziej avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.