All Projects → pheymann → specdris

pheymann / specdris

Licence: MIT License
A test framework for Idris

Programming Languages

Idris
72 projects
powershell
5483 projects
shell
77523 projects
HTML
75241 projects

Projects that are alternatives of or similar to specdris

Bash unit
bash unit testing enterprise edition framework for professionals
Stars: ✭ 419 (+661.82%)
Mutual labels:  unit-testing, test-framework, unittest
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-63.64%)
Mutual labels:  unit-testing, test-framework, unittest
tau
A Micro (1k lines of code) Unit Test Framework for C/C++
Stars: ✭ 121 (+120%)
Mutual labels:  unit-testing, test-framework
dumbmutate
Simple mutation-testing
Stars: ✭ 32 (-41.82%)
Mutual labels:  unit-testing, unittest
kmtest
Kernel-mode C++ unit testing framework in BDD-style
Stars: ✭ 42 (-23.64%)
Mutual labels:  unit-testing, test-framework
Zunit
A powerful testing framework for ZSH projects
Stars: ✭ 140 (+154.55%)
Mutual labels:  unit-testing, test-framework
Kotlinmvparchitecture
Clean MVP Architecture with Dagger2 + Retrofit2 + Mockito + Fresco + EasiestGenericRecyclerAdapter using Kotlin. Added Unit Tests(Kotlin Tests)!
Stars: ✭ 143 (+160%)
Mutual labels:  unit-testing, unittest
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (-25.45%)
Mutual labels:  unit-testing, test-framework
Qtools
QTools collection of open source tools for embedded systems development on Windows, Linux and MacOS
Stars: ✭ 64 (+16.36%)
Mutual labels:  unit-testing, test-framework
unittest expander
A library that provides flexible and easy-to-use tools to parameterize Python unit tests, especially those based on unittest.TestCase.
Stars: ✭ 12 (-78.18%)
Mutual labels:  unit-testing, unittest
jest-puppe-shots
A Jest plugin for creating screenshots of React components with a little help of Puppeteer
Stars: ✭ 86 (+56.36%)
Mutual labels:  unit-testing, unittest
oletus
Minimal ECMAScript Module test runner
Stars: ✭ 43 (-21.82%)
Mutual labels:  unit-testing, test-framework
Atoum
The modern, simple and intuitive PHP unit testing framework.
Stars: ✭ 1,382 (+2412.73%)
Mutual labels:  unit-testing, test-framework
Unit Threaded
Advanced unit test framework for D
Stars: ✭ 100 (+81.82%)
Mutual labels:  unit-testing, unittest
Truth
Fluent assertions for Java and Android
Stars: ✭ 2,359 (+4189.09%)
Mutual labels:  unit-testing, test-framework
Tcunit
An unit testing framework for Beckhoff's TwinCAT 3
Stars: ✭ 74 (+34.55%)
Mutual labels:  unit-testing, test-framework
testza
Full-featured test framework for Go! Assertions, fuzzing, input testing, output capturing, and much more! 🍕
Stars: ✭ 409 (+643.64%)
Mutual labels:  unit-testing, test-framework
Nunit cshaprp cheatsheet
Example implementations of each attribute available in Nunit2 unit Testing Framework using C# .NET.
Stars: ✭ 14 (-74.55%)
Mutual labels:  unit-testing, unittest
Data Mocks
Library to mock local data requests using Fetch or XHR
Stars: ✭ 55 (+0%)
Mutual labels:  unit-testing, test-framework
TestIt
Generate unit testing boilerplate from kotlin files.
Stars: ✭ 32 (-41.82%)
Mutual labels:  unit-testing, unittest

Build Status

specdris

With this framework you can write spec-like Unit Tests in Idris:

import Specdris.Spec

main : IO ()
main = spec $ do
  describe "This is my math test" $ do
    it "adds two natural numbers" $ do
      (1 + 1) `shouldBe` 2
    it "multiplies two natural numbers" $ do
      (2 * 2) `shouldBe` 3
    it "do fancy stuff with complex numbers" $ do
      pendingWith "do this later"

You can also nest describe. When executed this spec it will produce the following output:

This is my math test
  + adds two natural numbers
  + multiplies two natural numbers
    [x] not equal --red
        actual:   4
        expected: 3
  + do fancy stuff with complex numbers
    [] pending: do this later -- yellow
    
Failed: Total = 3, Failed = 1, Pending = 1 -- red

You can also test your IO code:

import Specdris.SpecIO

main : IO ()
main = specIO $ do
  describe "This is my side effect test" $ do
    it "say my name" $ do
      name <- loadName
      
      pure $ name `shouldBe` "Foo"

You can find more information about SpecIO here.

Both spec and specIO have backend-agnostic versions, respectively spec' and specIO', that use IO' rather than IO.

Install

This testing framework is written with Idris 1.0.

Clone the repo from github with git clone https://github.com/pheymann/specdris.git and run:

cd specdris
./project --install

# under windows
.\Project.ps1 --install

elba

If you use elba to manage your Idris packages, you can also add specdris as a dev-dependency to be run during tests. Just add the following to the [dev_dependencies] section of your package's elba.toml manifest:

[dev_dependencies]
# snip
"pheymann/specdris" = { git = "https://github.com/pheymann/specdris" }

Then you'll be able to use specdris from all test targets.

Documentation

Expectations

Currently this framework provides you with:

Expectation Alias Description
a shouldBe b === is a equal to b
a shouldNotBe b /== is a unequal to b
a shouldBeTrue is a True
a shouldBeFalse is a False
a shouldSatisfy pred satisfies a a given predicate
a shouldBeJust exp if a is Just a' apply exp to a'; here exp is again a sequence of expectations

Failed Test Cases

If an expectations in a test case failes the following expectations aren't executed and the whole case is marked as failure:

  it "failing test" $ do
    1 `shouldBe` 1 -- success
    2 `shouldBe` 1 -- failes
    2 `shouldBe` 2 -- will not be executed

SpecIO

Besides the usual test cases you can also add effects as:

BeforeAll

Executes an IO () before running any test case:

specIO {beforeAll = putStrLn "hello"} $ do ...

AfterAll

Executes an IO () after all test cases are executed:

specIO {afterAll = putStrLn "bye"} $ do ...

Around

Takes a function IO SpecResult -> IO SpecResult which can be used to execute IO code before and after every test case:

around : IO SpecResult -> IO SpecResult
around resultIO = do putStrLn "hello"
                     result <- resultIO
                     putStrLn "bye"
                     
                     pure result

specIO {around = around} $ do

Shuffle/Randomise Test Case Execution

You can randomise your test case execution by applying shuffle to your spec:

mySpec : SpecTree
mySpec = 
  describe "my test"
    it "a" $ 1 === 1
    it "b" $ 2 === 2

-- default seed
spec $ shuffle mySpec

-- static seed
spec $ shuffle mySpec 1000

-- current time
do seed <- System.time
   spec $ shuffle mySpec seed

shuffle only changes execution order for tests (it) under a decribe and thus preserves the logical test structure.

Creating your own Expectations

If you need other expections than these provided here you can implement them as follows:

shouldParse: (Show a, Eq, a) => Parser -> (actual : String) -> (expected : a) -> SpecResult
shouldParse: parser actual expected 
  = case parser actual of
      (Right result) => result === expected
      (Left err)     => UnaryFailure actual $ "couldn't parse: " ++ err

Working with SpecState

It is possible to get the SpecState record of a spec after its execution by using specWithState from Spec or SpecIO.

Storing Console Output in SpecState

If you want to process the output after spec execution you can store it in SpecState by setting spec {storeOutput = True} or specIO {storeOutput = True}. This also stops specdris from printing it to the console.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].