Questions tagged [expecto]

Questions related to usage of Expecto, the testing library. You can also ask related questions about its integrations with FsCheck, BenchmarkDotNet or Hopac here.

Expecto is a testing library for F#, written by Henrik Feldt:

  • F# syntax throughout, tests as values; write plain F# to generate tests
  • Use the built-in Expect module, or an external lib like Unquote for assertions
  • Parallel tests by default
  • Test your Hopac code or your Async code; Expecto is async throughout
  • Pluggable logging and metrics via Logary Facade; easily write adapters for build systems, or use the timing mechanism for building an InfluxDB+Grafana dashboard of your tests' execution times
  • Built in support for BenchmarkDotNet
  • Build in support for FsCheck; makes it easy to build tests with generated/random data or building invariant-models of your object's/actor's state space

Hello world looks like this

open Expecto

let tests =
  test "A simple test" {
    let subject = "Hello World"
    Expect.equal subject "Hello World" "The strings should equal"
  }

[<EntryPoint>]
let main args =
  runTestsWithArgs defaultConfig args tests
14 questions
6
votes
2 answers

Expecto FsCheck getting stack overflow exception when generating string

I'm trying to learn how to use FsCheck properly, and integrating it with Expecto at the moment. I can get property tests to run if I'm using the default FsCheck config, but when I try to use my own Generator, it causes a stack overflow…
kaeedo
  • 458
  • 2
  • 13
5
votes
1 answer

How to assert for an asynchronous exception in Expecto without RunSynchronously?

I have started to use F# Expecto framework and cannot find a proper way to assert for an exception in async computation expressions. My code ended up with: Expect.throws (fun () -> async { // Some async code expected to fail... …
ded'
  • 664
  • 4
  • 11
5
votes
1 answer

Expecto Test in F# always passes even when forced to fail

I'm trying to get expecto up and running in our test project. Though it compiles and run fine, I wanted to just make sure it was really working. So I gave it a fail case and it passes. Did I miss something silly here? My test setup let tests = …
DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
4
votes
1 answer

How to assert an exception is expected

I'm on a Mac running F# using .NET Core 2.0. I have a function that looks like this: let rec evaluate(x: string) = match x with // ... cases | _ -> failwith "illogical" I'd like to write an Expecto test that validates that the exception is…
neontapir
  • 4,698
  • 3
  • 37
  • 52
3
votes
1 answer

FsCheck with Setup and Teardown

Summary Are there any events that can be run before every property case so that I can run setup and teardown for each run of a property? Full version I want to be able to test paired behaviors like "I can always fetch written records" or "output of…
farlee2121
  • 2,959
  • 4
  • 29
  • 41
3
votes
1 answer

F#, VSCode and OSX: The namespace or module 'Expecto' is not defined

I am attempting to get started with F Sharp. I have mono installed via brew and dotnetcore installed via d/l. I have VS Code and the ionide plugin installed. I have done the following steps: project > new > expecto paket install fake…
Toby Hede
  • 36,755
  • 28
  • 133
  • 162
2
votes
1 answer

Expecto: log individual test statuses

I've got a test that occasionally flakes and crashes my test process. However, I can't figure out which test is causing the failure. The only output I get is How can I get test results to log as they happen so I can find the failing test?
farlee2121
  • 2,959
  • 4
  • 29
  • 41
2
votes
0 answers

Simple example for logging text in expecto test

I'm trying to write some logs in an Expecto test, however I can't figure out how to get anything to be logged. Is there a very simple example of this somewhere? Currently I have: module Test open Expecto open Expecto.Logging open…
Paul Johnson
  • 1,329
  • 1
  • 12
  • 25
2
votes
1 answer

How do I register my own FsCheck Generator on Expecto

I've built my generator type that generates multiples of three. I want to use it in a test with Expecto. How can register this generator and tell my test to use it? let multipleOfThree n = n * 3 type ThreeGenerator = static member…
ntonjeta
  • 43
  • 5
2
votes
2 answers

How to configure CI for dockerized F# Expecto tests on TFS

I have some dockerized F# tests written by expecto and fscheck frameworks, as a dotnet core standalone executable. How to configure continuous integration on Team Foundation Server to run them and get the report after each run accordingly?
Mohsen
  • 4,000
  • 8
  • 42
  • 73
1
vote
1 answer

How can I set Expecto configuration properties when running tests via Visual Studio test adapter

I'm using Expecto.VisualStudio.TestAdapter to integrate with Visual Studio 2017. How do I set configuration options for Expecto so that the Visual Studio test runner will pick them up? I specifically need to set parallel = false for a given test…
Coding Dude
  • 617
  • 1
  • 6
  • 16
1
vote
1 answer

F# Make Async[]> to Async[]

I get some list of data from a HTTP call. I then know what values to get for another HTTP call. I would like to have everything be asynchronous. But I need to use this data with Expecto's testCaseAsync : string -> Async -> Test. So, my goal is…
Jon49
  • 4,444
  • 4
  • 36
  • 73
0
votes
0 answers

System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it

I'm writing an integration test for a component that does a transaction and after that, a webhook is called. For that, I want to mock a webhook endpoint using suave so I can know if the webhook was hit after the transaction was done. I'm doing the…
Kanagawa Marcos
  • 100
  • 1
  • 9
0
votes
1 answer

How to set --summary in the test assembly in Expecto

Expecto allows you to set parameters via CLIArguments and also by overriding its defaultConfig. One of the parameters is --summary. Currently I just directly pass "--summary" and merge it with argv but is there a parameter (I assume 'printer') that…
s952163
  • 6,276
  • 4
  • 23
  • 47