SlideShare a Scribd company logo
1
Automated Testing
Part 1 – Unit Testing
Noah Ispas | Data One GmbH
2
»
• Why?
• Levels
• Unit Testing
• What is a unit?
• Scope
• Naming
• Anatomy
• Tight vs Loose Coupling
• Real World Scenario & Mocking
• Takeaways
Agenda
3
„Developer testing is an important step towards accountability. It gives developers a
way to demonstrate the quality of the software they produce.“ Kent Beck
4
Why?
• Prove that software works
• Regression
• Trust the code
• Test cases are specifications
• Refactoring
• Reduce manual testing
• Easier to locate errors
Why even write automated tests?
5
Levels
6
XUnit
• NuGet Dependencies
• Microsoft.NET.Test.SDK
• Xunit
• Xunit.runner.visualstudio
• Note: You can shoose a Xunit Project in VS, which already contains all
dependencies
• Keywords
• [Fact] as test method attribute
• Assert.*
7
What is a Unit ?
• A Function/Method
• A Collection of Functions/Methods
• A Whole Class
• -> The smaller the better
• -> The more isolated the more better
8
Unit Under Test
9
Scope/Test Cases & Naming
10
Anatomy of a Test Case
• Arange
• Act
• Assert
• Cleanup
11
Anatomy of a Test Case
12
That was a perfect world example …
… how about the reality?
13
More real example
Controller
Service
Database
Entities
14
• Loose coupling and Separation of Concerns are very important design principles
• What‘s the problem with tight coupling?
• Changing something without having to touch other places becomes hard
• Automated testing becomes hard
• What is the benefit of loose coupling?
• Better understandability
• Better maintainability
• Decreased risk when changing something
• Decreased cost of change!
Tight coupling is bad
15
Compare those
16
Compare those
• What if we want to extend SomeService and decide that SomeController
needs to use that extension?
• -> We have to also change SomeController in order to use the extension
17
Compare those
• Now we can simply inject the extension.
• -> Inversion of Control Principle (SomeService could be an abstraction)
• -> Dependency Injection
18
Unit Under Test
• What is the testing scope?
• -> We just want to test the controller
• -> All dependencies should be mocked
19
Moq
• NuGet Dependencies
• Moq
• Usage
• var mock = new Mock<ClassToBeMocked>();
• mock.Setup(mockedClass => mockedClass.method()).Returns(true)
• Placeholder for Parameters: It.IsAny<String>()
• A Mock is like a decorator for a class object. Reference the object with
Mock.Object
20
• A unit usually refers to a function/method or a whole class
• Arrange, Act, Assert
• Test the functionality isolated and mock every downstream dependency
• Don‘t be tricked by test coverage reports
• Line coverage does only mean that those lines are called in a unit test
• But lines can be called with the test assertion beeing shitty
• High Line Coverage does not mean that the actual Test Coverage is good
• Branch Coverage is a better metric, as it says something about which branches are called in unit tests
• Still the test cases have to make sense
• Don‘t test the code of 3rd party frameworks
• Design Principles help a lot
• Separation of Concerns
• Open Closed Principle -> Inversion of Control
• Dependency Injection
• Loose Coupling
Unit testing – Takeways
21
Fragen? »
22
• Play around with unit testing, those basics should be enough for adding solid
amount of unit tests -> build a routine (tasks are not done until there are no unit
tests)
• Even more advanced, real life scenarios (maybe using some code of existing
applications) -> how to handle refactoring and unit testing at the same time?!
• More precise mocking examples
• Pitfalls
• Integration Testing
• Deep Dive in Design Principles?!
What‘s Next
23
• https://github.com/moq/moq4
• https://xunit.net/
• https://docs.microsoft.com/en-us/visualstudio/test/unit-test-basics?view=vs-
2019
• https://stackify.com/unit-testing-basics-best-practices/
• https://medium.com/better-programming/unit-testing-best-practices-
9bceeafe6edf
Further Reading
24
www.dataone.de
• https://github.com/iamNoah1/Asp.NetCoreAutomatedTestTraining
• https://twitter.com/IamNoah1_

More Related Content

PPTX
Refactoring Legacy Web Forms for Test Automation
PPT
Intro to junit
PPTX
Moq presentation
PPTX
Unit tests and TDD
PPTX
Unit testing and mocking in Python - PyCon 2018 - Kenya
PPTX
Angular Unit Testing
PPTX
Presentation
Refactoring Legacy Web Forms for Test Automation
Intro to junit
Moq presentation
Unit tests and TDD
Unit testing and mocking in Python - PyCon 2018 - Kenya
Angular Unit Testing
Presentation

What's hot (20)

PPTX
Java Unit Test - JUnit
PPTX
Principles and patterns for test driven development
PDF
Unit Testing Fundamentals
PPTX
Unit test
PDF
Database development unit test with tSQLt
PDF
Unit testing (workshop)
PPTX
Grails Spock Testing
PDF
Unit test-using-spock in Grails
ODP
Grails unit testing
PPT
Integration testing
PDF
Unit Testing Done Right
PDF
Unit testing in Force.com platform
PDF
Testing in FrontEnd World by Nikita Galkin
PDF
What is UFT? HP's unified functional testing.
PDF
Ddc2011 효과적으로레거시코드다루기
PPT
Ppt Qtp
PPTX
j meter
PDF
Unit Testing Best Practices
PPTX
Testing the Untestable
PDF
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Java Unit Test - JUnit
Principles and patterns for test driven development
Unit Testing Fundamentals
Unit test
Database development unit test with tSQLt
Unit testing (workshop)
Grails Spock Testing
Unit test-using-spock in Grails
Grails unit testing
Integration testing
Unit Testing Done Right
Unit testing in Force.com platform
Testing in FrontEnd World by Nikita Galkin
What is UFT? HP's unified functional testing.
Ddc2011 효과적으로레거시코드다루기
Ppt Qtp
j meter
Unit Testing Best Practices
Testing the Untestable
Pitfalls Of Tdd Adoption by Bartosz Bankowski
Ad

Similar to Automated testing of ASP .Net Core applications (20)

PPT
Ch11lect1 ud
PPTX
Unit Testing
PPTX
Unit Testing in Swift
PPTX
Unit testing
PDF
Testing Angular
PDF
An Introduction to Unit Test Using NUnit
PDF
Devday2016 real unittestingwithmockframework-phatvu
PPTX
Test Driven Development
PPTX
Lecture (Software Testing).pptx
PPTX
Testing, a pragmatic approach
PPT
How to test models using php unit testing framework?
PPTX
Integration system acceptance test
PDF
CNUG TDD June 2014
PPTX
Level Up Your Salesforce Unit Testing
PPTX
Qt test framework
 
PPTX
Unit Testing talk
PDF
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
PPT
Software engineering Testing technique,test case,test suit design
PDF
Tests and Testability: Apex Structure and Strategy
PPTX
Object Oriented Testing
Ch11lect1 ud
Unit Testing
Unit Testing in Swift
Unit testing
Testing Angular
An Introduction to Unit Test Using NUnit
Devday2016 real unittestingwithmockframework-phatvu
Test Driven Development
Lecture (Software Testing).pptx
Testing, a pragmatic approach
How to test models using php unit testing framework?
Integration system acceptance test
CNUG TDD June 2014
Level Up Your Salesforce Unit Testing
Qt test framework
 
Unit Testing talk
[DevDay 2016] Real Unit Testing with mocking framework - Speaker: Phat Vu – S...
Software engineering Testing technique,test case,test suit design
Tests and Testability: Apex Structure and Strategy
Object Oriented Testing
Ad

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
top salesforce developer skills in 2025.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
L1 - Introduction to python Backend.pptx
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Digital Strategies for Manufacturing Companies
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
top salesforce developer skills in 2025.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
L1 - Introduction to python Backend.pptx
ManageIQ - Sprint 268 Review - Slide Deck
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
VVF-Customer-Presentation2025-Ver1.9.pptx
How Creative Agencies Leverage Project Management Software.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
Digital Strategies for Manufacturing Companies
Design an Analysis of Algorithms II-SECS-1021-03
Odoo POS Development Services by CandidRoot Solutions
Wondershare Filmora 15 Crack With Activation Key [2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Which alternative to Crystal Reports is best for small or large businesses.pdf

Automated testing of ASP .Net Core applications

  • 1. 1 Automated Testing Part 1 – Unit Testing Noah Ispas | Data One GmbH
  • 2. 2 » • Why? • Levels • Unit Testing • What is a unit? • Scope • Naming • Anatomy • Tight vs Loose Coupling • Real World Scenario & Mocking • Takeaways Agenda
  • 3. 3 „Developer testing is an important step towards accountability. It gives developers a way to demonstrate the quality of the software they produce.“ Kent Beck
  • 4. 4 Why? • Prove that software works • Regression • Trust the code • Test cases are specifications • Refactoring • Reduce manual testing • Easier to locate errors Why even write automated tests?
  • 6. 6 XUnit • NuGet Dependencies • Microsoft.NET.Test.SDK • Xunit • Xunit.runner.visualstudio • Note: You can shoose a Xunit Project in VS, which already contains all dependencies • Keywords • [Fact] as test method attribute • Assert.*
  • 7. 7 What is a Unit ? • A Function/Method • A Collection of Functions/Methods • A Whole Class • -> The smaller the better • -> The more isolated the more better
  • 10. 10 Anatomy of a Test Case • Arange • Act • Assert • Cleanup
  • 11. 11 Anatomy of a Test Case
  • 12. 12 That was a perfect world example … … how about the reality?
  • 14. 14 • Loose coupling and Separation of Concerns are very important design principles • What‘s the problem with tight coupling? • Changing something without having to touch other places becomes hard • Automated testing becomes hard • What is the benefit of loose coupling? • Better understandability • Better maintainability • Decreased risk when changing something • Decreased cost of change! Tight coupling is bad
  • 16. 16 Compare those • What if we want to extend SomeService and decide that SomeController needs to use that extension? • -> We have to also change SomeController in order to use the extension
  • 17. 17 Compare those • Now we can simply inject the extension. • -> Inversion of Control Principle (SomeService could be an abstraction) • -> Dependency Injection
  • 18. 18 Unit Under Test • What is the testing scope? • -> We just want to test the controller • -> All dependencies should be mocked
  • 19. 19 Moq • NuGet Dependencies • Moq • Usage • var mock = new Mock<ClassToBeMocked>(); • mock.Setup(mockedClass => mockedClass.method()).Returns(true) • Placeholder for Parameters: It.IsAny<String>() • A Mock is like a decorator for a class object. Reference the object with Mock.Object
  • 20. 20 • A unit usually refers to a function/method or a whole class • Arrange, Act, Assert • Test the functionality isolated and mock every downstream dependency • Don‘t be tricked by test coverage reports • Line coverage does only mean that those lines are called in a unit test • But lines can be called with the test assertion beeing shitty • High Line Coverage does not mean that the actual Test Coverage is good • Branch Coverage is a better metric, as it says something about which branches are called in unit tests • Still the test cases have to make sense • Don‘t test the code of 3rd party frameworks • Design Principles help a lot • Separation of Concerns • Open Closed Principle -> Inversion of Control • Dependency Injection • Loose Coupling Unit testing – Takeways
  • 22. 22 • Play around with unit testing, those basics should be enough for adding solid amount of unit tests -> build a routine (tasks are not done until there are no unit tests) • Even more advanced, real life scenarios (maybe using some code of existing applications) -> how to handle refactoring and unit testing at the same time?! • More precise mocking examples • Pitfalls • Integration Testing • Deep Dive in Design Principles?! What‘s Next
  • 23. 23 • https://github.com/moq/moq4 • https://xunit.net/ • https://docs.microsoft.com/en-us/visualstudio/test/unit-test-basics?view=vs- 2019 • https://stackify.com/unit-testing-basics-best-practices/ • https://medium.com/better-programming/unit-testing-best-practices- 9bceeafe6edf Further Reading

Editor's Notes