Generative Artificial Intelligence: How generative AI works.pdf
Starting Test Driven Development With Mock Objects
1.
2. Starting Test Driven Development with Mock objects Dror Helper Software Developer Typemock
3. Sounds familiar? Every ten bugs I fix I create a new one… I have no idea what caused that issue… I’d rather not change that function… It is impossible to Unit Test our project! Setting my test environment takes too long
4. Agenda Unit testing Introducing Test Driven Development Code new feature using TDD Writing unit tests using Isolation
5. Unit Tests Test specific functionality Clear pass/fail criteria Good unit test runs in isolation
6. What is a Unit Test [TestMethod] public void CheckPassword_ValidUser_ReturnTrue() { bool result = CheckPassword(“user”, “pass”); Assert.IsTrue(result); }
8. The Demo Project - UserAdmin Create function that saves new user:
9. The Demo Project –Tests Step 1 Check that name is not empty Check that email is not empty Check if user already in our database
10. Verify new user details Dror Helper Software Developer Typemock Demo
11. What is Isolation/Mocking Replace production logic with custom logic We do this in order to Focus the test on one class only Test interaction between components Break dependencies Simplify unit test writing
12. Set Behavior Return custom values Throw exceptions Ignore calls Run custom action when called
21. Want to learn more? Start using TDD in your project today! Read about TDD & Isolation on Typemock Insiders blog - blog.typemock.com Follow us on twitter.com/Typemock
AtomicRepeatableNo dependency between tests/test orderClear pass/fail criteria
TDD is about design and developmentBy testing first you design your code
Show Tests 1 & 2Start test 3 - AddNewUser_BothUserNameAndEmailExist_FinishNormally show exception from “Database”So what do we do now?
Isolation is a technique for replacing parts of the production logic with custom logic.We’ll use Typemock Isolator for the example but there are others – Moq, Rhino
First we start with the verification.Our user story tells us that the name and email should not be left empty and the user should not exist in our database