I have spent a ton of time doing testing for the last several weeks, so I get to teach my friends in a C# study group some basic testing in C# tomorrow. It’s been a minute since I’ve done this (February, maybe?). So I wanted to get the process down somewhere in case I go awhile without working in C# again.
I’m going to use the general idea of some of the mythical creatures exercises we did at Turing, because why not? I have no idea who wrote these originally, and that repo is what I found from a quick google.
That is what it looks like when I open VSCode. To set it up, go to the main project directory, and I am going to create a models directory to put the file inside of that
Anyway, now to set up the actual tests. I think the whole point of mythical creatures was to get more comfortable with test-driven development, so I’m going to turn the Ruby tests into C# tests, and see if I can think of a few more to add in to explore what XUnit can do. Few things to note before we get to the code. In xUnit, you add [Fact] above the test to mark it as a test method. [Theory] is one of the other ones, for parameterized tests, and I’ll try to think of a way to implement that too. If it’s not there, xUnit won’t recognize the method as a test. Basically, use [Fact] if there are no parameters and it is a standalone test.
This is the basic structure, with the namespace, public class, and all that stuff. It helps me to see it this way and fill things in