Comments (4)
Is this not the goal of the "equal" assertion failure message?
FsUnit nor any other testing framework does this. They only execute the ToString()
(or something similar) to have stringified values.
Especially in the implementation of NUnit FsUnit just consumes the NUnit constraints here: https://github.com/fsprojects/FsUnit/blob/master/src/FsUnit.NUnit/Equality.fs#L23
Anyway, this is not reasonable to do for us. We cannot implement every format for every specific type that has a "special" format.
Sorry for that.
from fsunit.
Many database (or thair drivers) store the datetime with the precision of milliseconds.
That is not enough when the original DateTime is written and then read back to guarantee the "equality".
The following is an example of a DateTime saved and read back on MongoDB 3.x:
DateTime differs only for fraction of milliseconds.
from fsunit.
Hey @alex-piccione,
I see the problem. I think the root cause is the underlaying .NET type system.
Let me figure it out:
When you create a DateTime
variable you get a date which you already see in your 2nd post with all the seconds, milliseconds and ticks etc..
Now, you want to test your record and the type system checks the types if they match and the values if they match, too. Values of the two DateTimes don't match and stringifies it to build a message with it.
The format is just %A
, in this result the code is like:
let date = System.DateTime.UtcNow in printfn "%A" date
the output is: 04.02.2022 08:09:59
(differs with culture, doesn't matter here)
You see, that milliseconds are not included.
My recommendation: Restructure your test(s) to test your DateTimes manually with milliseconds.
The result from your code above will be:
item.D.ToString "dd.MM.yyyy HH:mm:ss.ffff"
|> should equal (expectedItem.D.ToString "dd.MM.yyyy HH:mm:ss.ffff")
The summary of the output window will be:
Message:
String lengths are both 24. Strings differ at index 20.
Expected: "04.02.2022 08:26:53.1455"
But was: "04.02.2022 08:26:53.0355"
-------------------------------^
I hope that helps.
(P.S.: This could also be the solution for #200.) Just comment if you need further help with it.
from fsunit.
Hi, Thanks for the reply.
I know that I can manually test the dates equality in a way that provides a meaningfull message, but I think it should automatically be done by the simple assertion:
actual |> should equal expected
.
Is this not the goal of the "equal" assertion failure message? or it is not reasonable to do?
I have a lot of them, not just this one. Also, other items have more DateTime properties, not just one.
I need to use a simple "equal", sometime I created a function to do a custom equal, (e.g. "equalMyItem"), but I have enough to reinvent the wheel everytime... I need a generic one.
The best solution (for me) is to create my version/copy of "equal" (still not sure it is this one that creates the message, I need to find out).
Thanks.
from fsunit.
Related Issues (20)
- FsUnit does not work with Result HOT 2
- ofCase doesn't support generic union type HOT 2
- 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 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
- [Feature request] Creating custom constraints HOT 4
- 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
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.