Comments (4)
Hello @C0DK ,
it depends what type somePerson
is.
I assume that somePerson
is a complex type like a record or class. In case of that WithName
and/or HaveName
must support the same type as somePerson
.
Even so, I recommend assertions as simply as possible e.g.:
type Person = { Name: string; Age: int }
let somePerson = ... // function that returns: { Name = "test"; Age = 34 }
somePerson.Name
|> should equal "test"
// and perhaps:
somePerson.Age
|> should equal 34
from fsunit.
I'm new to FSharp so I might just take things to the extreme, but having a test that is simply one expression is neat (in my opinion), so it was simply to not have to access the property. Currently, I was doing:
somePerson
|> withName SomeName
|> getName
|> Should equal SomeName
Should I just use let
more rather than doing everything as a singular expression?
from fsunit.
Should I just use
let
more rather than doing everything as a singular expression?
No, that was just an example on my side for better readability.
You can also write from my example:
somePerson
|> fun p -> p.Name
|> should equal "test"
An extra constraint or operator in FsUnit would be too special, btw.
Use single/short functions to have a little toolset in your implementations.
from fsunit.
alright. Consider it closed then :) I might raise another ticket if i have a more complex case. In a c# project where we use NUnit, we do have custom constraints for specific things, like checking whether a StatusCode is "Succesful" (200 <= x < 300) based on NUnits custom constraints https://docs.nunit.org/articles/nunit/extending-nunit/Custom-Constraints.html - and i think that was my offset. but in this case i do see your point.
Thank you :) I also didn't think of using a fun p -> p.Name
rather than an explicit function defined above. neat!
from fsunit.
Related Issues (20)
- ofCase doesn't handle None (represented as null) HOT 3
- equalWithin on DU types of float HOT 6
- Implementing Expecto HOT 6
- `result |> should be (ofCase <@ Ok @>)` throws exception at runtime HOT 3
- Error message when DateTime is not equal does not provide any help HOT 4
- Error message for "equal" is difficult to read and does not show the date milliseconds also when that is the only difference
- Method not found: 'Void Xunit.Sdk.AssertActualExpectedException..ctor HOT 2
- Pipelines are not correctly failing HOT 3
- Inconsistent behaviour of `should equal` in NUnit vs XUnit HOT 1
- Update docs site HOT 7
- error FS0074: The type referenced through 'NHamcrest.IMatcher`1' is defined in an assembly that is not referenced. HOT 2
- Using `should throw` does not show the raised exception, only the string version of the lambda HOT 5
- Using 'should throw' or 'should throwWithMessage' never succeeds unless function returns unit HOT 15
- Deep equality for C# types HOT 5
- Comparing sequences fails HOT 13
- New Year's ToDos HOT 1
- Is FSharp.Core 6.0.7 really the lowest dependency for FsUnit? HOT 3
- `MatchException` does not exist anymore in 2.5.0 HOT 2
- Do not use an upper bound on dependencies, unless you have to HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsunit.