• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    F#
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lean .NET BDD framework with powerful F# integration

Build Status NuGet Status Join the chat at https://gitter.im/fsprojects/TickSpec

Project Description

A lightweight Behaviour Driven Development (BDD) framework for .NET that'll fit how you want to test.

  1. Describe behaviour in plain text using the Gherkin business language, i.e. Given, When, Then.
  2. Easily execute the behaviour against matching F# 'ticked' methods, or attribute-tagged C# or F# methods.
  3. Run via your normal test runners or plugins (xUnit, NUnit or standalone)
  4. Set breakpoints in the scenarios, step definitions or your code and go (setting breakpoints in the Gherkin is currently not supported in .NET Standard version)

Example video: http://www.youtube.com/watch?v=UuTL3nj9fIE

Installation

Simply reference TickSpec via NuGet or Paket, download the assembly or build the project from source.

Feature specification (Plain text)

Feature: Refunded or replaced items should be returned to stock

Scenario: Refunded items should be returned to stock
    Given a customer buys a black jumper
    And I have 3 black jumpers left in stock
    When he returns the jumper for a refund
    Then I should have 4 black jumpers in stock

Step definitions (F#)

type StockItem = { Count : int }

let mutable stockItem = { Count = 0 }

let [<Given>] ``a customer buys a black jumper`` () = ()

let [<Given>] ``I have (.*) black jumpers left in stock`` (n:int) =
    stockItem <- { stockItem with Count = n }

let [<When>] ``he returns the jumper for a refund`` () =
    stockItem <- { stockItem with Count = stockItem.Count + 1 }

let [<Then>] ``I should have (.*) black jumpers in stock`` (n:int) =
    let passed = (stockItem.Count = n)
    Debug.Assert(passed)

Step definitions (F# without mutable field)

type StockItem = { Count : int }

let [<Given>] ``a customer buys a black jumper`` () = ()
      
let [<Given>] ``I have (.*) black jumpers left in stock`` (n:int) =
    { Count = n }
      
let [<When>] ``he returns the jumper for a refund`` (stockItem:StockItem) =
    { stockItem with Count = stockItem.Count + 1 }
      
let [<Then>] ``I should have (.*) black jumpers in stock`` (n:int) (stockItem:StockItem) =
    let passed = (stockItem.Count = n)
    Debug.Assert(passed)

Step definitions (C#)

public class StockStepDefinitions
{
   private StockItem _stockItem;

   [Given(@"a customer buys a black jumper")]
   public void GivenACustomerBuysABlackJumper()
   {
   }

   [Given(@"I have (.*) black jumpers left in stock")]
   public void GivenIHaveNBlackJumpersLeftInStock(int n)
   {
      _stockItem = new StockItem() { Count = n };
   }

   [When(@"he returns the jumper for a refund")]
   public void WhenHeReturnsTheJumperForARefund()
   {
      _stockItem.Count += 1;
   }

   [Then(@"I should have (.*) black jumpers in stock")]
   public void ThenIShouldHaveNBlackJumpersInStock(int n)
   {
      Debug.Assert(_stockItem.Count == n);
   }
}

Type Conversions

Arguments to Step Methods will be converted from string to the declared types of the Step Method parameters when possible. The following conversions are supported:

  • Enum types
  • Union types with no parameters
  • Nullable<T> types where the inner T type can be converted from string
  • Tuple types where each element can be converted from string
  • Array types T [] where T can be converted from string and the original string is comma delimited
  • Types supported by System.Convert.ChangeType

Tables

A table may be passed as an argument to a Step Method:

When a market place has outright orders:
   | Contract | Bid Qty | Bid Price | Offer Price | Offer Qty |
   | V1       | 1       | 9505      |             |           |
   | V2       |         |           | 9503        | 1         |

The parameter can be declared with type Table:

let [<When>] ``a market place has outright orders:`` (table:Table) =
    outrightOrders <- toOrders table

Alternatively, the parameter can be converted to an array of records, or other type with constructor parameters supported by the Type Conversions

type OrderRow = { Contract: string; BidQty: string; BidPrice: string; OfferPrice: string; OfferQty: string }

let [<When>] ``a market place has outright orders:`` (orderRows: OrderRow[]) =
    outrightOrders <- toOrders orderRows

The Table parameter must appear after any regex capture parameters, and before any Functional Injection parameters:

let [<Given>] ``A market place``() =
    createMarketPlace()

let [<When>] ``a market place has outright (.*) orders:``
    (orderType: string)       # captured
    (table: Table)            # table
    (maketPlace: MarketPlace) # injected
    =
  ...

Lists

A bullet list may be passed to a Step Method similarly to a Table:

Scenario: Who is the one?
Given the following actors:
    * Keanu Reeves
    * Bruce Willis
    * Johnny Depp
When the following are not available:
    * Johnny Depp
    * Bruce Willis
Then Keanu Reeves is the obvious choice

The parameter type must be an array type supported by the Type Conversions:

let [<Given>] ``the following actors:`` (actors : string[]) =
    availableActors <- Set.ofArray actors

Advanced features

Resolving referenced types (beta)

As shown in Step definitions (F# without mutable field), TickSpec also allows one to request additional parameters along with the captures from the regex holes in the step name as per typical Gherkin based frameworks. Such additional parameters can be fulfilled via the following mechanisms:

  • Instances returned from Step Method return values: This involves generating and stashing an instance in one of the preceding steps in the scenario. Typically this is achieved by returning the instance from the Step Method. Whenever a step has a return value, the the value is saved under it's type (the return type of the Step Method controls what the type is). Multiple values can be returned from a Step Method by returning a tuple. There can be only one value per type stashed per scenario run. When a parameter is being resolved, TickSpec first attempts to resolve from this type-to-instance caching Dictionary.

  • Resolving dependencies: If an instance cannot be located in the type-to-instance cache based on a preceding step having stashed the value, TickSpec will attempt to use the 'widest' constructor (the one with the most arguments) of the required type to instantiate it. Any input arguments to the constructor are all resolved recursively using the same mechanism. Any constructed instances are also cached in the type-to-instance cache, so next time it will return the same instance.

  • Accessing scenario metadata: You can access contextual information about the scenario within which a step definition is executing (e.g. tags). To do this, add a parameter of type ScenarioMetadata in the step definition argument list (or in a constructor parameter list of a dependency) scenario information (e.g. tags), then you can reference ScenarioMetadata in your method argument (or in constructor of dependencies) and you will get an instance describing the scenario which is invoked.

The lifetime of instances is per-scenario:- Each scenario run starts an empty type-to-instance cache, and at the end of the scenario the cache gets cleared. Moreover, if any instance is IDisposable, Dispose will be called.

See the example projects DependencyInjection and FunctionalInjection for typical and advanced examples of using this mechanism.

Custom type resolver (beta)

While the typical recommended usage of TickSpec is to keep the step definitions simple and drive a system from the outside in the simplest fashion possible, in some advanced cases it may be useful to provide a custom type resolver. This can be achieved by setting the StepDefinitions.ServiceProviderFactory property. This factory method is used once per scenario run to establish an independent resolution context per scenario run. The IServiceProvider instance is used to replace the built in instance construction mechanism (see Resolving dependencies in the previous section: Resolving referenced types). If the IServiceProvider implementation yielded by the factory also implements IDisposable, Dispose is called on the Service Provider context at the end of the scenario run.

See the CustomContainer example project for usage examples - the example demonstrates wiring of Autofac including usage of lifetime scopes per scenario and usage of the xUnit 2+ Shared Fixtures to correctly manage the sharing/ifetime of the container where one runs xUnit Test Classes in parallel as part of a large test suite.

Contributing

Contributions are welcome, particularly examples and documentation. If you'd like to chat about TickSpec, please use the the gitter channel.

For issues or suggestions please raise an Issue. If you are looking to extend or change the core implementation, it's best to drop a quick note and/or a placeholder PR in order to make sure there is broad agreement on the scope of the change / nature of the feature in question before investing significant time on it; we want to keep TickSpec powerful, but minimal.

More Repositories

1

Paket

A dependency manager for .NET with support for NuGet packages and Git repositories.
F#
2,019
star
2

FAKE

FAKE - F# Make
F#
1,279
star
3

awesome-fsharp

A curated list of awesome F# frameworks, libraries, software and resources.
1,194
star
4

Avalonia.FuncUI

Develop cross-plattform GUI Applications using F# and Avalonia!
F#
952
star
5

FSharpPlus

Extensions for F#
F#
845
star
6

FSharp.Data

F# Data: Library for Data Access
F#
813
star
7

fantomas

FSharp source code formatter
F#
772
star
8

FSharpx.Extras

Functional programming and other utilities from the original "fsharpx" project
F#
683
star
9

Rezoom.SQL

Statically typechecks a common SQL dialect and translates it to various RDBMS backends
F#
670
star
10

SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
F#
578
star
11

ProjectScaffold

A prototypical .NET solution (file system layout and tooling), recommended for F# projects
F#
517
star
12

FSharp.Formatting

F# tools for generating documentation (Markdown processor and F# code formatter)
F#
464
star
13

Argu

A declarative CLI argument parser for F#
F#
454
star
14

FsHttp

A lightweight F# HTTP library by @SchlenkR and @dawedawe
F#
445
star
15

IfSharp

F# for Jupyter Notebooks
Jupyter Notebook
442
star
16

FsUnit

FsUnit makes unit-testing with F# more enjoyable. It adds a special syntax to your favorite .NET testing framework.
F#
425
star
17

FSharp.Data.GraphQL

FSharp implementation of Facebook GraphQL query language.
F#
399
star
18

fsharp-companies

Community curated list of companies that use F#
385
star
19

fsharp-cheatsheet

This cheatsheet aims to succinctly cover the most important aspects of F# 6.0.
F#
328
star
20

zarchive-fsharpbinding

Archive of F# Language Bindings for Open Editors
Emacs Lisp
308
star
21

FSharpLint

Lint tool for F#
F#
303
star
22

pulsar-client-dotnet

Apache Pulsar native client for .NET (C#/F#/VB)
F#
301
star
23

FSharp.TypeProviders.SDK

The SDK for creating F# type providers
F#
298
star
24

FSharp.Control.Reactive

Extensions and wrappers for using Reactive Extensions (Rx) with F#.
F#
284
star
25

SwaggerProvider

F# generative Type Provider for Swagger
F#
264
star
26

FsReveal

FsReveal parses markdown and F# script file and generates reveal.js slides.
F#
258
star
27

FSharp.Data.Adaptive

On-demand adaptive/incremental data for F# https://fsprojects.github.io/FSharp.Data.Adaptive/
F#
249
star
28

FSharpx.Collections

FSharpx.Collections is a collection of datastructures for use with F# and C#.
F#
247
star
29

FSharp.Json

F# JSON Reflection based serialization library
F#
226
star
30

fsharp-language-server

F#
219
star
31

fsharp-ai-tools

TensorFlow API for F# + F# for AI Models eDSL
F#
213
star
32

FsLexYacc

Lexer and parser generators for F#
F#
207
star
33

FSharp.Data.SqlClient

A set of F# Type Providers for statically typed access to MS SQL database
F#
205
star
34

Fleece

Json mapper for F#
F#
199
star
35

ExcelFinancialFunctions

.NET Standard library providing the full set of financial functions from Excel.
F#
194
star
36

Chessie

Railway-oriented programming for .NET
F#
187
star
37

FsXaml

F# Tools for working with XAML Projects
F#
172
star
38

FSharp.UMX

F# units of measure for primitive non-numeric types
F#
162
star
39

FSharp.Control.AsyncSeq

Asynchronous sequences for F#
F#
161
star
40

Paket.VisualStudio

Manage your Paket (http://fsprojects.github.io/Paket/) dependencies from Visual Studio!
C#
147
star
41

ExcelProvider

This library is for the .NET platform implementing a Excel type provider.
F#
141
star
42

SIMDArray

SIMD enhanced Array operations
F#
132
star
43

FsBlog

Blog aware, static site generation using F#.
CSS
132
star
44

FSharp.Configuration

The FSharp.Configuration project contains type providers for the configuration of .NET projects.
F#
114
star
45

FSharp.Interop.Dynamic

DLR interop for F# -- works like dynamic keyword in C#
F#
95
star
46

FSharpx.Async

Asynchronous programming utilities for F#
F#
94
star
47

FSharp.Control.TaskSeq

A computation expression and module for seamless working with IAsyncEnumerable<'T> as if it is just another sequence
F#
93
star
48

FSharp.Management

The FSharp.Management project contains various type providers for the management of the machine.
F#
91
star
49

AzureStorageTypeProvider

An F# Azure Type Provider which can be used to explore Blob, Table and Queue Azure Storage assets and easily apply CRUD operations on them.
F#
84
star
50

Foq

A unit testing framework for F#
F#
79
star
51

FSharp.Azure.Storage

F# API for using Microsoft Azure Table Storage service
F#
75
star
52

FSharp.ViewModule

Library providing MVVM and INotifyPropertyChanged support for F# projects
F#
74
star
53

FSharp.Text.RegexProvider

A type provider for regular expressions.
F#
74
star
54

Incremental.NET

A library for incremental computations. Based on janestreet/incremental (https://github.com/janestreet/incremental) for OCaml.
F#
72
star
55

FSharp.Core.Fluent

Fluent members for F# FSharp.Core functions
F#
71
star
56

Mechanic

F#
68
star
57

FSharp.Collections.ParallelSeq

Parallel (multi-core) sequence operations
F#
68
star
58

FSharp.Quotations.Evaluator

A quotations evaluator/compiler for F# based on LINQ expression tree compilation
F#
68
star
59

FSharp.Linq.ComposableQuery

Compositional Query Framework for F# Queries, based on "A Practical Theory of Language-Integrated Query"
F#
67
star
60

OpenAPITypeProvider

F# type provider for Open API specification
F#
65
star
61

fsharp-hashcollections

Library providing fast hash based immutable map and set
F#
60
star
62

FSharp.AWS.DynamoDB

F# wrapper API for AWS DynamoDB
F#
58
star
63

FSharp.Data.Toolbox

F# Data-based library for various data access APIs
F#
57
star
64

DynamoDb.SQL

SQL-like external DSL for querying and scanning Amazon DynamoDB
F#
54
star
65

FsRandom

A purely-functional random number generator framework designed for F#
F#
52
star
66

Z3Fs

Simple DSL to solve SMT problems using Z3 API in F#
F#
52
star
67

FSharp.Data.JsonSchema

F#
49
star
68

fantomas-for-vs

Visual Studio Formatter for F#
HTML
46
star
69

SyntacticVersioning

Helper tool to verify semantic version changes based on API surface area changes
F#
45
star
70

FSharp.Compatibility

Compatibility libraries for F#
F#
44
star
71

Interstellar

Cross-platform desktop apps in F# using web tech - https://www.nuget.org/packages/Interstellar.Core/
F#
43
star
72

FSharp.Interop.PythonProvider

Early experimental F# type provider for python
F#
42
star
73

FSharp.Compiler.PortaCode

The PortaCode F# code format and corresponding interpreter. Used by Fabulous and others.
F#
42
star
74

FSharp.CloudAgent

Allows running F# Agents in a distributed manner using Azure Service Bus.
F#
39
star
75

FSharp.Data.TypeProviders

F# Type Providers for SqlDataConnection, SqlEntityConnection, ODataService, WsdlService and EdmxFile using .NET Framework generators
F#
38
star
76

Roslyn.FSharp

Roslyn read-only API to work with F# code (via bridge to FSharp.Compiler.Service)
F#
37
star
77

FnuPlot

An F# wrapper for gnuplot charting library
F#
35
star
78

GraphProvider

A state machine type provider
F#
35
star
79

FSharp.Span.Utils

Makes Span/ReadOnlySpan easy to use from F#.
F#
34
star
80

fantomas-tools

Collection of tools used when developing for Fantomas
F#
34
star
81

fsharp-linting-for-vs

Visual Studio Linter for F#
C#
33
star
82

LocSta

An F# library for composing state-aware functions by @SchlenkR
JavaScript
33
star
83

FSharp.Data.Xsd

XML Type Provider with schema support
F#
32
star
84

zarchive-sublime-fsharp-package

F# development tools for SublimeText 3
Python
32
star
85

.github

The place to request for projects to be added or removed from the incubation space
28
star
86

zarchive-xamarin-monodevelop-fsharp-addin

(No longer Used) F# Editing Support In MonoDevelop and Xamarin Studio
F#
27
star
87

Zander

Regular expression for matrix information. I.e. parse structured blocks of information from csv or excel files (or similar 2d matrixes)
F#
27
star
88

FSharp.Compiler.CodeDom

An F# CodeDOM implementation (based on the old F# Power Pack)
F#
25
star
89

BioProviders

F# library for accessing and manipulating bioinformatic datasets.
F#
24
star
90

ReasoningEngine

Symbolic analysis of discrete dynamical systems
F#
24
star
91

FSharp.Data.WsdlProvider

An implementation of the WsdlProvider compatible with netfx and netcore
F#
24
star
92

FsMath3D

F# 3D Math Library for realtime applications
F#
22
star
93

S3Provider

Experimental type provider for Amazon S3
F#
22
star
94

FSharpPerf

A set of performance test scripts for the F# compiler.
F#
20
star
95

MarkerClustering

A component to cluster map markers.
F#
19
star
96

DynamicsCRMProvider

A type provider for Microsoft Dynamics CRM 2011.
F#
16
star
97

Amazon.SimpleWorkflow.Extensions

Extensions to AmazonSDK's SimpleWorkflow capabilities to make it more intuitive to use
F#
16
star
98

Canopy.Mobile

Canopy testing framework for mobile apps
F#
14
star
99

LSON

Lisp inspired serialization (intended for when you don't even want to take a dependency on JSON serializer)
F#
14
star
100

FSharp.Codecs.Redis

FSharp redis codecs based on Fleece patterns
F#
13
star