Add collection constraints from NUnit
See original GitHub issueDescription
I just wrote some tests and wanted to test a collection that has the equivalent item than another.
Could you please implement the collection constraints from NUnit?
Repro steps
I have to use NUnit’s function with like:
let areCollectionsEqual = CollectionAssert.AreEquivalent([1;2;3], [3;1;2])
It’s not so “F#-ish”.
Known workarounds
I “extended” FsUnit with an extra function:
module FsUnit =
open NUnit.Framework.Constraints
let equalsToCollection x = CollectionEquivalentConstraint x
So I can use this function like:
let areCollectionsEqual () = [1;2;3] |> should equalsToCollection [3;1;2]
Collection contraints implemented:
- equivalent
- supersetOf
- subsetOf
Issue Analytics
- State:
- Created 4 years ago
- Comments:18 (15 by maintainers)
Top Results From Across the Web
Custom Constraints
You can implement your own custom constraints by creating a class that inherits from the Constraint abstract class, which supports performing a test...
Read more >Collection Constraints (NUnit 2.4 / 2.5)
Collection constraints perform tests that are specific to collections. The following collection constraints are provided. Before NUnit 2.4.6, ...
Read more >NUnit.Framework.Constraints Namespace
Explore all classes and interfaces of the NUnit. ... Represents a constraint that succeeds if all the members of a collection match a...
Read more >Today I Learned How to Create Custom NUnit Constraints
The first step in creating a NUnit custom constraint is to read the documentation. ... Add whatever logic you need to to the...
Read more >Creating a NUnit constraint meaning "{collection} does not ...
If you are using NUnit 2.4 / 2.5 you may checkout the collection constraints. Share.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would like to implement the
subsetOf
operator, too. To have the counterpart ofsupersetOf
.Like:
[4;5] |> should be (subsetOf [1..10])
Is this okay?
I guess
CollectionAssert.AreEqual
case should be covered byequal
operator due to structured equality(we may add such test-cases and check)
for NUnit and MSTest is make sense to wrap
CollectionAssert.AreEquivalent
intoequivalent
operator. I am not sure about xUnit, we can leave it not implemented because it is not idiomatic for framework or reimplement logic from NUnit on our side