I started writing about and giving presentations last year. This year, our company has decided to use that material and give a “Getting started with Unit Testing workshop”. I’ve given this 3 times now at Omnitech. Once to a pilot group, then to our normal Tuesday Lunch and Learn group, then to those who didn’t make it. I’ve been improving from feedback each time. I’m thankful for leadership that have seen the importance of automated testing to the quality of our code and to our organization. I was alloted some time to work on this.
Here’s the format I used.
To get people writing tests and get over the “but” stage of not testing.
We’ll take a simple, slightly pre-baked tests and write them together with Kevin narrating.
Get familiar with some reasons why you should test, etc
Bonus: Read the Art of Unit testing (we are starting a book club soon in Feb/March 2019!, maybe you should too)
Switch to the workshop branch, we’ll be working from
Requires VS 2017 (latest), .Net Core 2.2 (or newer as time goes on), node.js ( https://nodejs.org/en/ , LTS, this is installed with VS if you check the right feature) You’ll need .Net Core 2.2 installed, check your Add or Remove programs or in the command line dotnet –version Download from https://dotnet.microsoft.com/download/dotnet-core/2.2 => get the sdk, if you don’t have *
From the PowerPoint linked above
Terms Slide #3
What should we test? Slide #7
dotnet new mstest -o Temp.Tests
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>aaa</Title> <Shortcut>aaa</Shortcut> <Description>AAA for tests</Description> <Author>Microsoft Corporation</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <Snippet> <Declarations> </Declarations> <Code Language="csharp"><![CDATA[ // Arrange // Act // Assert ]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>
Test Naming: Class_Action_Modifier_ExpectedResult " have decent titles that communicate their intent." Organization in the test explorer is important. I usually look at it by category.
We are doing TDD “light” with removing comments from code walk through following along
Given an API call When asking for current temp and no zip code is given Then returns a 400
Type it out, don’t just un comment
Pause for questions and for people to catch up.
Given a request to Apixu to get the temp When given a zip code It Returns the temp
Given a request to Apixu to get the temp When given a zip code It uses that zip code // not the best, most needed test?
No validation, that’s the controller job in this application (for better or worse)
If you’re close to Sioux Falls, SD or want to do a remote workshop, let me know on Twitter and we can work something out.
Please consider using Brave and adding me to your BAT payment ledger. Then you won't have to see ads! (when I get to $100 in Google Ads for a payout, I pledge to turn off ads)
Also check out my Resources Page for referrals that would help me.