4 ms·
My teams use a snippet that expands to the following [Fact(Skip = "Generated With Snippet")] public async Task MyTestMethodAsync() { //Arrang
by hvidgaard 5y ago
My teams use a snippet that expands to the following
[Fact(Skip = "Generated With Snippet")]
public async Task MyTestMethodAsync()
{
//Arrange
//Act
//Assert
throw new NotImplementedException();
}
If that results in hard to read unittests I suspect that your library would too, as it is a matter discipline. If we assume that we use your terms, "Given, When, Then" in place of "Arrange, Act, Assert" - can you give an argument that would favour your solution with the syntactic overhead of putting it all in lambdas?
- moogly 5y agoAh, my pet peeve. I also prefer AAA tests, but I can't stand it when people leave those comments in as some kind of region markers. IMO, they're useful when teaching AAA tests, but it seems, in my experience, most developers actually have those comments in every. single. test. That's some hardcore cargo culting. I just use a blank line to separate the different stages, and if you have problems making that readable, you probably need to refactor the Arrange or Assert parts to use some helper methods. I realize I'm probably overreacting, but I feel the anger rising whenever I see this in the wild (and have to suppress it).
- hvidgaard 5y agoIt's to ensure that it's actually adhered to. Unfortunately experience have shown that it's unreasonable to expect all developers to remember this on their own accord. I generally also advise the leads to make sure there is a reasonable limit to the length of a test method. As you say if it's too long it probably needs some work before it's allowed in the main branch.
- pc86 5y agoYou can always just overwrite the comments with the first line of code. If this actually makes you angry and you're not just hyperbolizing for literary flair you need to see a therapist.
- moogly 5y ago> You can always just overwrite the comments with the first line of code. I of course mean leaving the comments in the final test. I don't care about the comments in the actual snippet.
- lozenge 5y ago"given a csv file when a column is missing then it is named in the thrown exception" Vs "arrange a csv with a missing column act read it assert the exception contains the missing column name"
- hvidgaard 5y agoI already covered that. > If we assume that we use your terms, "Given, When, Then" in place of "Arrange, Act, Assert"