Skip to content

Migration from MSTest and improved assertions#614

Merged
dennisdoomen merged 1 commit intofluentassertions:release-5.0from
jnyrup:best-practices
Oct 3, 2017
Merged

Migration from MSTest and improved assertions#614
dennisdoomen merged 1 commit intofluentassertions:release-5.0from
jnyrup:best-practices

Conversation

@jnyrup
Copy link
Member

@jnyrup jnyrup commented Aug 5, 2017

As promised in #585 here is a list of 104 examples about:

  • Converting from MSTest to Fluent Assertions.
  • Rewriting assertions for clearer intentions and better failure messages.

Comments on the preface and the layout are very welcome.

@dennisdoomen
Copy link
Member

Thanks for the great work.

Isn't this just about migrating from MSTest?

Where do we want to display this? As a header on the landing page?

@jnyrup
Copy link
Member Author

jnyrup commented Aug 6, 2017

The first 44 examples, are about migrating from MSTest.
The last 60 examples are on rewriting FA assertions.

Yes, I thought next to documentation or examples.

@dennisdoomen
Copy link
Member

I see now. So what's next? I see it's still WIP.

@jnyrup
Copy link
Member Author

jnyrup commented Aug 6, 2017

I have implemented failing tests for all examples, and thought about including the failure message for all examples to give proof how the rewrites improves.

@Meir017
Copy link
Member

Meir017 commented Aug 6, 2017

are there plan for writing Analyzers for the rewrites?

@jnyrup
Copy link
Member Author

jnyrup commented Aug 6, 2017

@Meir017 I don't have any concrete plans.
But only because I don't have any experience in writing analyzers.

@dennisdoomen
Copy link
Member

I'll keep ignoring this PR as long as it's WIP. Tell me if this is no longer the case.

@jnyrup
Copy link
Member Author

jnyrup commented Aug 16, 2017

I still want to add the failure messages to each example, so it's still WIP.

@SaroTasciyan, you mentioned some examples you wanted to add.

@SaroTasciyan
Copy link
Contributor

Almost all of the items in my list (NUnit) is covered. Missing ones are assertions regarding; string equivalency, DateTime and some others which might not have an equivalent in MSTest. If that's the case, I don't see the value it would add since they are already covered in the documentation.

Regarding the best practices part; It can be extended (in time) with chained assertions (And, Which), ShouldBeEquivalentTo, string equivalency / wildcard and FleuntDateTimeExtensions demonstration.

@jnyrup
Copy link
Member Author

jnyrup commented Aug 17, 2017

They don't need to have a MSTest equivalent, as long as there is a "wrong" and a "right" way to write it.

When you're new to FA, even after reading the documentation (for the first time), you might not be familiar with how to write idiomatic assertions.
These docs give examples, where you can search by fragments of your smelly assertion to find better alternatives.

@SaroTasciyan
Copy link
Contributor

In my opinion, they don't need to go into this part.

Converting from MSTest to Fluent Assertions.

That's why I listed them in this part (which I assume is best practices)

Rewriting assertions for clearer intentions and better failure messages.

</tr></table>


## [ExpectedException]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding the Assert.ThrowsException equivalent as well, that is if this also applies for MSTest V2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't even know MSTest V2 had that assertion.
I think it should be included.
It also great advertisement why to upgrade to MSTest V2

In fact, this is my favorite example, as the MSTest V1 way is quite ugly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jnyrup
Copy link
Member Author

jnyrup commented Sep 6, 2017

I have finished adding the examples and failure messages I had planned.
The remaining part would be layout.
I'm not familiar with how GitHub markdown turns out as html, but when looking at the .md file, the are multiple things I'm unsatisfied with:

  • The margins, that you have to scroll horizontally.
  • That snippets are not top+left aligned.
  • Missing whitespace conservation.
  • Better syntax highlighting?
  • A Table of Contents.

Layout is really not my strong side, so could use ideas/help, if this should become prettier.
@adamvoss You seem to be an expert?

@dennisdoomen dennisdoomen changed the base branch from develop to release-5.0 September 18, 2017 05:15
@adamvoss
Copy link
Contributor

@jnyrup I am really sorry I keep letting this slip through the cracks. I will try looking into this tomorrow, and if not then for sure this coming week.

@adamvoss
Copy link
Contributor

adamvoss commented Sep 24, 2017

I lied, I just took a quick peak now. It looks like there is an error in the HTML because I get a nesting table, but didn't take time to track it down.

Try this for inspiration (its not great but should give some ideas on things you can do):

<table>
<thead>
<tr>
    <th>
        MSTest
    </th>
    <th>
        FluentAssertions
    </th>
</tr>
<tr>
    <th>
        Failure Message
    </th>
    <th>
        Failure Message
    </th>
</tr>
</thead>
<tbody>
<tr>
<td markdown="1">
```c#
Assert.IsTrue(actual);
```
</td>
<td markdown="1">
```c#
actual.Should().BeTrue();
```
</td>
</tr><tr>
<td markdown="1">
> Assert.IsTrue failed.
</td>
<td markdown="1">
> Expected True, but found False.
</td>
</tr>
</tbody></table>

Some of the problems will need to be fixed via CSS. Regarding the page itself, if wanted to structure data into CSVs, I can help you use Liquid templates to build populate a table and avoid the sort of issue it has now with an error somewhere in the table.

TOC can be done automatically too (see the documentation page):

## Table of Contents ##
* TOC
{:toc}

Good work!

@jnyrup
Copy link
Member Author

jnyrup commented Sep 27, 2017

Thanks for the tips @adamvoss that helped a lot
The pages are now generated with Jekyll using Liquid templates to fetch the data from yaml files.

As there to my knowledge isn't a way to see the generated page here without pushing to master, here are two screenshots:
untitled

untitled2

@adamvoss
Copy link
Contributor

Wow, I ran it locally and that was a great step!

The next part is really out of my area of expertise. Does anyone reading this have design or CSS experience?

Someone who really knows this stuff could probably do some responsive design stuff that makes it flow well onto mobile too.

If it is just me trying to figure this out, my approach would probably be:

  • Make the tables a fixed width (based on the current SASS variable for content width)
  • Make the messages word-wrap when they would be too long for the box
  • Manually add line breaks in the assertions multi-line if they would be too long on their own.

layout: page
---

<link href="/assets/css/syntax.css" rel="stylesheet" >
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is different or better in this syntax highlighting over the existing highlighting in this project?

@adamvoss
Copy link
Contributor

adamvoss commented Oct 1, 2017

I have proposed two pull request to this which hopefully will bring it close to completion:

jnyrup#1
jnyrup#2

@adamvoss
Copy link
Contributor

adamvoss commented Oct 1, 2017

I have made some final suggestions at jnyrup#3. Once those changes are decided on I'd recommend squashing the history. (I don't know if you have strong opinions on squashing or if @dennisdoomen will require it, this just looks like history that is better squashed to me; don't worry about squashing my commits, I don't need attribution for them). Then I'd recommend @dennisdoomen review it for possible inclusion.

My only nit-pick would be that the horizontal scroll bar on code blocks should never appear when the windows is maximized (on a sufficiently large screen). But, since all the examples are "close enough" I am not motivated enough by the issue to recommend blocking on that issue.

@jnyrup
Copy link
Member Author

jnyrup commented Oct 1, 2017

@adamvoss GitHub has a squash-and-merge function, so no worries.

@adamvoss
Copy link
Contributor

adamvoss commented Oct 1, 2017

GitHub has a squash-and-merge function, so no worries.

It is generally not a big deal and I cannot speak for Dennis on this front, but I can give the perspective from being as a package maintainer elsewhere. While GitHub added the squash option, when contributors expect the maintainer to use it shifts the responsibility for writing a good commit message to the maintainer. Instead of everything presented as-desired so all you have to do is confirm its good and click the merge button, you have to stop and think up a good message.

There is plenty of room on GitHub for different usage patterns, so choosing not to squash is still a correct/valid decision.

@dennisdoomen
Copy link
Member

I prefer properly squashed and documented commits myself. This is what I require in my professional projecs and which I practice myself. So if somebody offers me a PR with three commits, I assume this person carefully squashed his work into these three commits and will merge them as is. If the PR only includes a single commit, I'll squash-merge it.

@jnyrup
Copy link
Member Author

jnyrup commented Oct 2, 2017

Thanks for the clarifications both of you, it makes perfect sense.
My laziness should not shift the burden onto anyone else.

I don't have any outstanding issues left, so from my perspective it's done.

@dennisdoomen
Copy link
Member

Well, then somebody should remove the WIP prefix.

@jnyrup jnyrup changed the title [WIP] Best practices Migration from MSTest and improved assertions Oct 2, 2017
@dennisdoomen dennisdoomen merged commit 4530dbd into fluentassertions:release-5.0 Oct 3, 2017
@jnyrup jnyrup mentioned this pull request Oct 3, 2017
@jnyrup jnyrup deleted the best-practices branch December 3, 2017 09:09
@Meir017 Meir017 mentioned this pull request Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants