SlideShare a Scribd company logo
STAATLICH
ANERKANNTE
FACHHOCHSCHULE
Author: Dip.-Inf. (FH) Johannes Hoppe
Date: 17.11.2010
01.12.2010
STUDIEREN
UND DURCHSTARTEN.
STAATLICH
ANERKANNTE
FACHHOCHSCHULE
RIA – Rich Internet Applications
Author: Dip.-Inf. (FH) Johannes Hoppe
Date: 17.11.2010
01.12.2010
Unit Tests in General
01
30.01.2015
Folie 3
Unit Tests in General
Dependencies
› Every meaningful piece of software has dependencies
to other pieces of software
30.01.2015
Folie 4
SoftwareA
SoftwareB
SoftwareC
Unit Tests in General
Dependencies
› But usually software is tightly coupled to other software
› Tightly coupled software is untestable!
30.01.2015
Folie 5
SoftwareA
SoftwareB
SoftwareC
Unit Tests in General
Dependencies
› We will concentrate on two types of dependencies:
1. A dependency by parameters:
ClassA { Method(ClassB b) {…}}
30.01.2015
Folie 6
SoftwareA
SoftwareB
SoftwareC
Unit Tests in General
Dependencies
2. A dependency by the internal use of the “new” keyword:
Class A {
Method() {
var c = new ClassC();
}}
30.01.2015
Folie 7
SoftwareA
SoftwareB
SoftwareC
Unit Tests in General
Dependencies – Solution
› Our golden tools:
Interfaces & Dependency Injection
30.01.2015
Folie 8
SoftwareA
ISoftwareB
ISoftwareC
SoftwareB
SoftwareC
Unit Tests in General
Interfaces
› Interfaces are blueprints that describe a real implementation
› Method are going to be independent
from the concrete implementation of the parameter:
ClassA { Method(ISoftwareB b) {…}}
30.01.2015
Folie 9
SoftwareA
ISoftwareB
ISoftwareC
SoftwareB
SoftwareC
Unit Tests in General
Dependency Injection
› We completely avoid the usage of the “new” keyword
› Instead, we are “injecting” the required instance
from outside by using Interfaces
› “Poor Man’s”-DI through constructor (works for UT, but is an anti-pattern!)
› by a framework (here: Unity Application Block):
ClassA {
[Dependency]
public InterfaceC C { private get; set; }
}
30.01.2015
Folie 10
Unit Tests in General
Loosely Coupled
1. If all dependencies are hidden by Interfaces
2. We must not always use real-live objects
3. We could also “cheat” with any object we want
(as long as it is implementing the interface)
 Unit Testing!!
30.01.2015
Folie 11
Unit Tests in General
30.01.2015
Folie 12
Definitions
› SUT == System Under Test
› Needs to be “fooled” so that it things it is talking with real collaborators
› Dummy
› Objects passed around but never actually used
› Used to fill required parameters in Unit Tests
› Fake
› Objects with working implementations, but not suitable for production
(e.g. in memory database with hardcoded data)
› Often used in software prototypes
› Should not be used in unit tests, too
Unit Tests in General
30.01.2015
Folie 13
Definitions
› Stubs
› Simple hand-written test-objects
› Set up the environment for the Unit Test by returning hardcoded values
 can be used for:
state verification
 Determine whether the exercised method worked correctly by
examining the state of the SUT and its collaborators
after the method was exercised.
Unit Tests in General
30.01.2015
Folie 14
Definitions
› Mocks
› More complex test-objects
› pre-programmed with expectations which form a specification of the calls
they are expected to receive*
 can be used for:
behavior verification
 Determine whether the exercised method worked correctly by
checking if the SUT made the
correct calls on the collaborators.
(* according to the definition of Martin Fowler)
Unit Tests in General
Definitions
› Many people (including me) are mixing the terms stub, fake and mock
› Mocking frameworks
› Can create Mocks with a lot of magic inside
› Can be used to build simple stubs, too!
30.01.2015
Folie 15
Unit Tests in General
Glossary
› MsTest – The unit testing framework that comes with Visual Studio
› Nunit – A quite popular unit testing framework which is open source
www.nunit.org
› Moq –A mocking framework that easy to use because of the lambda
expression syntax
www.moq.me
30.01.2015
Folie 16
Unit Tests in General
Questions
?
30.01.2015
Folie 17
Review of our first Unit Test
02
30.01.2015
Folie 18
Unit Tests
30.01.2015
Folie 19
How?
Review of our first Unit Test
Explanation of Code
30.01.2015
Folie 20
Review of our first Unit Test
Dependencies
30.01.2015
Folie 21
WebNoteRepository
IWebNote
IObjectSet<Note>
Review of our first Unit Test
Dependencies
IWebNote – Entity Framework:
IWebNote – by our own Mock:
30.01.2015
Folie 22
WebNoteRepository
IWebNote
Review of our first Unit Test
30.01.2015
Folie 23
WebNoteRepository
IWebNote
IObjectSet<Note>
Dependencies
IObjectSet<Note> – Entity Framework:
IObjectSet<Note> – by our own Mock:
Chaining
› Real live: by poor man’s DI
› Unit Test: automatically by the class WebNoteBaseRepositoryTest
› From which we are inheriting in our UT
Review of our first Unit Test
30.01.2015
Folie 24
Chaining
Unit Tests in General
30.01.2015
Folie 25
Mocked Repository
Base class from which we are inheriting
Required to prepare the mock
Unit Tests
Your tasks from last week:
› Try to write your first set of unit tests
› Work together with you neighbor (2 persons, one team)
› Use the Mock-Framework “Moq” from www.moq.me
› Implement:
 AddNoteTest, EditNoteTest, DeleteNoteTest
 DeleteNoteShouldThrowExceptionTest
 GetNoteShouldNotCallSaveChangesTest
 6 Tests for the Controller
30.01.2015
Folie 26
Unit Tests
03
30.01.2015
Folie 27
Unit Tests
Tests: only with stubs
30.01.2015
Folie 28
Unit Tests
30.01.2015
Folie 29
Unit Tests
30.01.2015
Folie 30
Unit Tests
30.01.2015
Folie 31
Unit Tests
30.01.2015
Folie 32
Unit Tests
30.01.2015
Folie 33
Unit Tests
Tests: with Mocks
30.01.2015
Folie 34
Unit Tests
30.01.2015
Folie 35
Unit Tests
30.01.2015
Folie 36
Unit Tests
30.01.2015
Folie 37
Unit Tests
30.01.2015
Folie 38
behavior verification! 
THANK YOU
FOR YOUR ATTENTION
30.01.2015
Folie 39

More Related Content

What's hot

Beginning iOS unit testing
Beginning iOS unit testingBeginning iOS unit testing
Beginning iOS unit testing
ski081
 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015
Buşra Deniz, CSM
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
Abhishek Yadav
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
Andrey Oleynik
 
Unit Testing in Android
Unit Testing in AndroidUnit Testing in Android
Unit Testing in Android
Md Shamsul Arafin Mahtab
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?
Steven Mak
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
BugRaptors
 
TestNG
TestNGTestNG
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
Narendran Solai Sridharan
 
TestNg_Overview_Config
TestNg_Overview_ConfigTestNg_Overview_Config
TestNg_Overview_Config
Abhishek Chakraborty
 
TDD - Unit Testing
TDD - Unit TestingTDD - Unit Testing
TDD - Unit Testing
SurajSavaratkar
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
Edureka!
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
Gousalya Ramachandran
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
Abhishek Yadav
 

What's hot (14)

Beginning iOS unit testing
Beginning iOS unit testingBeginning iOS unit testing
Beginning iOS unit testing
 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
 
Unit Testing in Android
Unit Testing in AndroidUnit Testing in Android
Unit Testing in Android
 
Is this how you hate unit testing?
Is this how you hate unit testing?Is this how you hate unit testing?
Is this how you hate unit testing?
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
 
TestNG
TestNGTestNG
TestNG
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
 
TestNg_Overview_Config
TestNg_Overview_ConfigTestNg_Overview_Config
TestNg_Overview_Config
 
TDD - Unit Testing
TDD - Unit TestingTDD - Unit Testing
TDD - Unit Testing
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
 

Similar to RIA 06 & 07 - Unit Testing in Detail

Ria 04 & 05 - First ASP.NET MVC project
Ria 04 & 05 - First ASP.NET MVC projectRia 04 & 05 - First ASP.NET MVC project
Ria 04 & 05 - First ASP.NET MVC project
Johannes Hoppe
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!
Return on Intelligence
 
Loopt unit test experiences
Loopt unit test experiencesLoopt unit test experiences
Loopt unit test experiences
Heine Frifeldt
 
Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012
Hong Le Van
 
Top 20 Junit interview questions for sdet
Top 20 Junit interview questions for sdetTop 20 Junit interview questions for sdet
Top 20 Junit interview questions for sdet
DevLabs Alliance
 
Continuous Integration testing based on Selenium and Hudson
Continuous Integration testing based on Selenium and HudsonContinuous Integration testing based on Selenium and Hudson
Continuous Integration testing based on Selenium and Hudson
Zbyszek Mockun
 
Open Source tools in Continuous Integration environment (case study for agil...
Open Source tools in Continuous Integration environment  (case study for agil...Open Source tools in Continuous Integration environment  (case study for agil...
Open Source tools in Continuous Integration environment (case study for agil...
suwalki24.pl
 
Introduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnitIntroduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnit
Mindfire Solutions
 
Beautfiul world of Flutter Testing
Beautfiul world of Flutter TestingBeautfiul world of Flutter Testing
Beautfiul world of Flutter Testing
Max Weber
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
Facundo Farias
 
Unit Testing and Why it Matters
Unit Testing and Why it MattersUnit Testing and Why it Matters
Unit Testing and Why it Matters
yahyaSadiiq
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
Deepak Singhvi
 
Engineering Student MuleSoft Meetup#4 - API Testing With MuleSoft
Engineering Student MuleSoft Meetup#4 - API Testing With MuleSoftEngineering Student MuleSoft Meetup#4 - API Testing With MuleSoft
Engineering Student MuleSoft Meetup#4 - API Testing With MuleSoft
Jitendra Bafna
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mocking
mrjawright
 
Dependency Injection in .NET applications
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applications
Babak Naffas
 
The 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web FrameworksThe 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web Frameworks
Kunal Ashar
 
Test driven development(tdd)
Test driven development(tdd)Test driven development(tdd)
Test driven development(tdd)
Omar Youssef Shiha
 
Munit_in_mule_naveen
Munit_in_mule_naveenMunit_in_mule_naveen
Munit_in_mule_naveen
VenkataNaveen Kumar
 
Testing your applications with mbunit
Testing your applications with mbunitTesting your applications with mbunit
Testing your applications with mbunit
Ben Hall
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
Hong Le Van
 

Similar to RIA 06 & 07 - Unit Testing in Detail (20)

Ria 04 & 05 - First ASP.NET MVC project
Ria 04 & 05 - First ASP.NET MVC projectRia 04 & 05 - First ASP.NET MVC project
Ria 04 & 05 - First ASP.NET MVC project
 
Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!Unit Tests? It is Very Simple and Easy!
Unit Tests? It is Very Simple and Easy!
 
Loopt unit test experiences
Loopt unit test experiencesLoopt unit test experiences
Loopt unit test experiences
 
Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012Tutorial test driven development with Visual Studio 2012
Tutorial test driven development with Visual Studio 2012
 
Top 20 Junit interview questions for sdet
Top 20 Junit interview questions for sdetTop 20 Junit interview questions for sdet
Top 20 Junit interview questions for sdet
 
Continuous Integration testing based on Selenium and Hudson
Continuous Integration testing based on Selenium and HudsonContinuous Integration testing based on Selenium and Hudson
Continuous Integration testing based on Selenium and Hudson
 
Open Source tools in Continuous Integration environment (case study for agil...
Open Source tools in Continuous Integration environment  (case study for agil...Open Source tools in Continuous Integration environment  (case study for agil...
Open Source tools in Continuous Integration environment (case study for agil...
 
Introduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnitIntroduction To UnitTesting & JUnit
Introduction To UnitTesting & JUnit
 
Beautfiul world of Flutter Testing
Beautfiul world of Flutter TestingBeautfiul world of Flutter Testing
Beautfiul world of Flutter Testing
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Unit Testing and Why it Matters
Unit Testing and Why it MattersUnit Testing and Why it Matters
Unit Testing and Why it Matters
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
Engineering Student MuleSoft Meetup#4 - API Testing With MuleSoft
Engineering Student MuleSoft Meetup#4 - API Testing With MuleSoftEngineering Student MuleSoft Meetup#4 - API Testing With MuleSoft
Engineering Student MuleSoft Meetup#4 - API Testing With MuleSoft
 
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, MockingTest Driven Development:Unit Testing, Dependency Injection, Mocking
Test Driven Development:Unit Testing, Dependency Injection, Mocking
 
Dependency Injection in .NET applications
Dependency Injection in .NET applicationsDependency Injection in .NET applications
Dependency Injection in .NET applications
 
The 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web FrameworksThe 2014 Decision Makers Guide to Java Web Frameworks
The 2014 Decision Makers Guide to Java Web Frameworks
 
Test driven development(tdd)
Test driven development(tdd)Test driven development(tdd)
Test driven development(tdd)
 
Munit_in_mule_naveen
Munit_in_mule_naveenMunit_in_mule_naveen
Munit_in_mule_naveen
 
Testing your applications with mbunit
Testing your applications with mbunitTesting your applications with mbunit
Testing your applications with mbunit
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 

More from Johannes Hoppe

2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
NoSQL - Hands on
NoSQL - Hands onNoSQL - Hands on
NoSQL - Hands on
Johannes Hoppe
 
Einführung in Angular 2
Einführung in Angular 2Einführung in Angular 2
Einführung in Angular 2
Johannes Hoppe
 
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und IonicMDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
Johannes Hoppe
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure
Johannes Hoppe
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
Johannes Hoppe
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
Johannes Hoppe
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
Johannes Hoppe
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript Security
Johannes Hoppe
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade
Johannes Hoppe
 
2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db
Johannes Hoppe
 
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
Johannes Hoppe
 
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGLJohannes Hoppe
 
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und MongodbJohannes Hoppe
 
2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL
Johannes Hoppe
 
2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB
Johannes Hoppe
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
Johannes Hoppe
 
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
Johannes Hoppe
 
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDBJohannes Hoppe
 

More from Johannes Hoppe (20)

2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach
 
NoSQL - Hands on
NoSQL - Hands onNoSQL - Hands on
NoSQL - Hands on
 
Einführung in Angular 2
Einführung in Angular 2Einführung in Angular 2
Einführung in Angular 2
 
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und IonicMDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach
 
2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript Security
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade
 
2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db
 
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
 
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
 
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
 
2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL
 
2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
 
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
 
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
 

Recently uploaded

Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
FODUU
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 

Recently uploaded (20)

Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 

RIA 06 & 07 - Unit Testing in Detail

  • 1. STAATLICH ANERKANNTE FACHHOCHSCHULE Author: Dip.-Inf. (FH) Johannes Hoppe Date: 17.11.2010 01.12.2010 STUDIEREN UND DURCHSTARTEN.
  • 2. STAATLICH ANERKANNTE FACHHOCHSCHULE RIA – Rich Internet Applications Author: Dip.-Inf. (FH) Johannes Hoppe Date: 17.11.2010 01.12.2010
  • 3. Unit Tests in General 01 30.01.2015 Folie 3
  • 4. Unit Tests in General Dependencies › Every meaningful piece of software has dependencies to other pieces of software 30.01.2015 Folie 4 SoftwareA SoftwareB SoftwareC
  • 5. Unit Tests in General Dependencies › But usually software is tightly coupled to other software › Tightly coupled software is untestable! 30.01.2015 Folie 5 SoftwareA SoftwareB SoftwareC
  • 6. Unit Tests in General Dependencies › We will concentrate on two types of dependencies: 1. A dependency by parameters: ClassA { Method(ClassB b) {…}} 30.01.2015 Folie 6 SoftwareA SoftwareB SoftwareC
  • 7. Unit Tests in General Dependencies 2. A dependency by the internal use of the “new” keyword: Class A { Method() { var c = new ClassC(); }} 30.01.2015 Folie 7 SoftwareA SoftwareB SoftwareC
  • 8. Unit Tests in General Dependencies – Solution › Our golden tools: Interfaces & Dependency Injection 30.01.2015 Folie 8 SoftwareA ISoftwareB ISoftwareC SoftwareB SoftwareC
  • 9. Unit Tests in General Interfaces › Interfaces are blueprints that describe a real implementation › Method are going to be independent from the concrete implementation of the parameter: ClassA { Method(ISoftwareB b) {…}} 30.01.2015 Folie 9 SoftwareA ISoftwareB ISoftwareC SoftwareB SoftwareC
  • 10. Unit Tests in General Dependency Injection › We completely avoid the usage of the “new” keyword › Instead, we are “injecting” the required instance from outside by using Interfaces › “Poor Man’s”-DI through constructor (works for UT, but is an anti-pattern!) › by a framework (here: Unity Application Block): ClassA { [Dependency] public InterfaceC C { private get; set; } } 30.01.2015 Folie 10
  • 11. Unit Tests in General Loosely Coupled 1. If all dependencies are hidden by Interfaces 2. We must not always use real-live objects 3. We could also “cheat” with any object we want (as long as it is implementing the interface)  Unit Testing!! 30.01.2015 Folie 11
  • 12. Unit Tests in General 30.01.2015 Folie 12 Definitions › SUT == System Under Test › Needs to be “fooled” so that it things it is talking with real collaborators › Dummy › Objects passed around but never actually used › Used to fill required parameters in Unit Tests › Fake › Objects with working implementations, but not suitable for production (e.g. in memory database with hardcoded data) › Often used in software prototypes › Should not be used in unit tests, too
  • 13. Unit Tests in General 30.01.2015 Folie 13 Definitions › Stubs › Simple hand-written test-objects › Set up the environment for the Unit Test by returning hardcoded values  can be used for: state verification  Determine whether the exercised method worked correctly by examining the state of the SUT and its collaborators after the method was exercised.
  • 14. Unit Tests in General 30.01.2015 Folie 14 Definitions › Mocks › More complex test-objects › pre-programmed with expectations which form a specification of the calls they are expected to receive*  can be used for: behavior verification  Determine whether the exercised method worked correctly by checking if the SUT made the correct calls on the collaborators. (* according to the definition of Martin Fowler)
  • 15. Unit Tests in General Definitions › Many people (including me) are mixing the terms stub, fake and mock › Mocking frameworks › Can create Mocks with a lot of magic inside › Can be used to build simple stubs, too! 30.01.2015 Folie 15
  • 16. Unit Tests in General Glossary › MsTest – The unit testing framework that comes with Visual Studio › Nunit – A quite popular unit testing framework which is open source www.nunit.org › Moq –A mocking framework that easy to use because of the lambda expression syntax www.moq.me 30.01.2015 Folie 16
  • 17. Unit Tests in General Questions ? 30.01.2015 Folie 17
  • 18. Review of our first Unit Test 02 30.01.2015 Folie 18
  • 20. Review of our first Unit Test Explanation of Code 30.01.2015 Folie 20
  • 21. Review of our first Unit Test Dependencies 30.01.2015 Folie 21 WebNoteRepository IWebNote IObjectSet<Note>
  • 22. Review of our first Unit Test Dependencies IWebNote – Entity Framework: IWebNote – by our own Mock: 30.01.2015 Folie 22 WebNoteRepository IWebNote
  • 23. Review of our first Unit Test 30.01.2015 Folie 23 WebNoteRepository IWebNote IObjectSet<Note> Dependencies IObjectSet<Note> – Entity Framework: IObjectSet<Note> – by our own Mock:
  • 24. Chaining › Real live: by poor man’s DI › Unit Test: automatically by the class WebNoteBaseRepositoryTest › From which we are inheriting in our UT Review of our first Unit Test 30.01.2015 Folie 24
  • 25. Chaining Unit Tests in General 30.01.2015 Folie 25 Mocked Repository Base class from which we are inheriting Required to prepare the mock
  • 26. Unit Tests Your tasks from last week: › Try to write your first set of unit tests › Work together with you neighbor (2 persons, one team) › Use the Mock-Framework “Moq” from www.moq.me › Implement:  AddNoteTest, EditNoteTest, DeleteNoteTest  DeleteNoteShouldThrowExceptionTest  GetNoteShouldNotCallSaveChangesTest  6 Tests for the Controller 30.01.2015 Folie 26
  • 28. Unit Tests Tests: only with stubs 30.01.2015 Folie 28
  • 34. Unit Tests Tests: with Mocks 30.01.2015 Folie 34
  • 39. THANK YOU FOR YOUR ATTENTION 30.01.2015 Folie 39