TDD Flashcards
In TDD, what is a Dummy?
They are simple mocks that represent external resources. They usual return the same result regardless of input parameters or number of times called
In TDD, what are Stubs/Fakes?
Similar to Dummy objects, but they will return a different result depending on the input parameters, however they still have no ‘knowledge’ of how many times they’ve been called
In TDD, what are Mocks?
They are a step up from Stubs/Fakes. Not only do they return different results depending on the input, they also have rules defining how often and when methods should be called
What types of methods should you NOT mock?
Private Methods
Convert the following function so that it’s Mocked to allow any integer value when called and always return 10 in a test: class MyClass() { public int WhatIsTheSquareOf(int x) { return x*x;} }
private Mock _myClass; _myClass.Setup(x => x.WhatIsTheSquareOf(It.IsAny()).Returns(10);
When you find / are told of a bug, what should be the first thing you do?
Write a unit test to ‘prove’ the bug. You’re fix should then stop the text from failing.
What are the 3 stages of a Unit Test?
Arrange
Act
Assert