SlideShare a Scribd company logo
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
BLG 411E – Software Engineering 
Recitation Session 3 
Test-Driven Development 
Atakan Aral, Bilge Süheyla Akkoca 
11.11.2014
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
Outline 
1 Introduction 
2 Unit Tests 
JUnit 
3 Auto Tests 
Cucumber 
4 Mock Objects 
Mockito 
5 References
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
TDD 
Definition 
A software development process. 
Based on text-first concept in Extreme Programming. 
Relies on the repetition of a very short development 
cycle. 
Also called Red-Greed-Refactor
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
TDD 
Life-cycle 
1 Write a test 
Before implementation 
2 Run the test 
Should fail 
3 Write the implementation code 
Just enough to pass the test 
Not perfect 
4 Run all tests 
All should pass 
5 Refactor 
Optimize code without introducing new features 
Should not make any tests fail 
Should not include new tests 
6 Repeat
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
TDD 
Features 
All about speed: short unit tests (JUnit), imperfect but 
fast code. 
Forces us to think before coding. 
Allows us to develop fast without being afraid to break 
something. 
Allows us to refactor with confidence. 
External dependencies should be mocked (mockito). 
So that we can test without other parts implemented. 
So out tests run faster (For instance, a DB connection). 
This forces us to separate concerns (DB instance can 
be replaced easily). 
A note 
Tools that we will introduce today do not belong to TDD. You 
can use them with any process.
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
TDD 
Behavior-Driven Development (BDD) 
An extension to TDD. 
In TDD, the tests may target class and methods (state) 
instead of their actual purpose (behaviour). 
Purpose of the user story is clearly related to the 
business outcomes. 
Single notation and ubiquitous language to improve 
communication (Gherkin language). 
Scenario’s are used instead of tests to avoid 
technicalities. 
Test can be generated automatically (cucumber).
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
Unit Testing 
Definition 
A white-box testing method for individual units of code. 
A unit is the smallest testable part of an application. 
Function in procedural programming 
Interface, class or method in object-oriented 
programming. 
Should be easy to write and fast to execute. 
Each unit test should be independent of others. 
Helps to identify problems early and to refactor easily.
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
JUnit 
JUnit is a test framework which uses annotations to 
identify methods that specify a test. 
@Test, @Test (expected = Exception.class), 
@Test(timeout=100), @Before, @After, @BeforeClass, 
@AfterClass, @Ignore 
JUnit provides static methods to test for certain 
conditions. 
fail, assertTrue, assertFalse, assertEquals, assertNull, 
assertNotNull, assertSame, assertNotSame
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
Test Automation 
Definition 
Manual testing usually takes too much time and 
resources. 
Tests can be automatically generated from BDD style 
descriptions. 
Tests can be fully automated as a part of build process. 
Watchers can be used to detect changes in the code, 
recompile if necessary, and run the tests.
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
Cucumber 
Cucumber is a BDD tool that executes plain-text 
functional descriptions as automated tests. 
Step definitions in Gherkin (Given, When, Then, And, 
But) are matched to a piece of code. 
If the step is matched and the code does not raise an 
Exception, the step is successful (green). 
If the step is not matched to any code, the step is 
pending (yellow). 
If the step is matched and the code raises an 
Exception, the step is failed (red).
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
Test Doubles 
A Vocabulary 
Dummy No implementation, just to fill the parameter list 
Stub Minimal implementation, returns hard-coded values 
Spy Similar to stub, also records invoked members 
Fake Have a simple implementation with some 
shortcuts, e.g. in-memory DB instead of real one 
Mock Dynamically created by a mock library, can be 
configured to return values, expect particular 
members to be invoked, etc.
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
Test Doubles 
Stub vs. Mock 
public void t e s tOr d e rSe n d sMa i l I fUn f i l l e d ( ) { / / Stub 
Order order = new Order (TALISKER, 51) ; 
Mai lServiceStub mai ler = new Mai lServiceStub ( ) ; 
order . setMai ler ( mai ler ) ; 
order . f i l l ( warehouse ) ; 
asser tEquals (1 , mai ler . numberSent ( ) ) ; 
} 
public void t e s tOr d e rSe n d sMa i l I fUn f i l l e d ( ) { / / Mock 
Order order = new Order (TALISKER, 51) ; 
Mock warehouse = mock (Warehouse . class ) ; 
Mock mai ler = mock ( Mai lService . class ) ; 
order . setMai ler ( ( Mai lService ) mai ler . proxy ( ) ) ; 
mai ler . expects ( once ( ) ) . method ( " send " ) ; 
warehouse . expects ( once ( ) ) . method ( " hasInventory " ) 
. withAnyArguments ( ) 
. w i l l ( returnValue ( false ) ) ; 
order . f i l l ( (Warehouse ) warehouse . proxy ( ) ) ; 
}
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
Mockito 
Behavior can be defined using when, thenReturn, 
thenThrow, thenAnswer methods. 
myClass myMock = mock(myClass.class); 
when(myMock.myMethod(5)) 
.thenReturn("five"); 
Behavior can be verified using verify method. 
verify(myMock).myMethod(12); 
verify(myMock).myMethod(anyInt()); 
verify(myMock) 
.myMethod(argThat(isValid())); 
verify(myMock, times(2)).myMethod(any()); 
verify(myMock, atMost(3)).myMethod(5); 
verifyNoMoreInteractions(myMock); 
inOrder.verify(myMock, atLeast(2)) 
.myMethod(5); 
inOrder.verify(myMock, times(1)) 
.myMethod(4);
BLG 411E 
Software 
Engineering 
Recitation 3 
Introduction 
Unit Tests 
JUnit 
Auto Tests 
Cucumber 
Mock Objects 
Mockito 
References 
References and Further Reading 
http://technologyconversations.com/2014/09/30/ 
test-driven-development-tdd/ 
http://technologyconversations.com/2013/12/20/ 
test-driven-development-tdd-example-walkthrough/ 
http://dannorth.net/introducing-bdd/ 
Meszaros, Gerard (2007). xUnit Test Patterns: 
Refactoring Test Code. Addison-Wesley. ISBN 
978-0-13-149505-0. 
http://msdn.microsoft.com/en-us/magazine/cc163358.aspx 
http://junit.org/ 
https://github.com/cucumber/cucumber/wiki 
https://code.google.com/p/mockito/

More Related Content

What's hot

Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnitGreg.Helton
 
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG Greg.Helton
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtestWill Shen
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesDerek Smith
 
Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnitinTwentyEight Minutes
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove
 
Mutation Testing and MuJava
Mutation Testing and MuJavaMutation Testing and MuJava
Mutation Testing and MuJavaKrunal Parmar
 
Google test training
Google test trainingGoogle test training
Google test trainingThierry Gayet
 
JUnit 5 - The Next Generation
JUnit 5 - The Next GenerationJUnit 5 - The Next Generation
JUnit 5 - The Next GenerationKostadin Golev
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with JunitValerio Maggio
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With PytestEddy Reyes
 
Software Testing and the R language
Software Testing and the R languageSoftware Testing and the R language
Software Testing and the R languageLou Bajuk
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Qualityguest268ee8
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveAlvaro Videla
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldDror Helper
 

What's hot (20)

Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
 
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG
 
20111018 boost and gtest
20111018 boost and gtest20111018 boost and gtest
20111018 boost and gtest
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Mutation testing
Mutation testingMutation testing
Mutation testing
 
Cursus phpunit
Cursus phpunitCursus phpunit
Cursus phpunit
 
Unit testing best practices with JUnit
Unit testing best practices with JUnitUnit testing best practices with JUnit
Unit testing best practices with JUnit
 
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible MistakesRoy Osherove on Unit Testing Good Practices and Horrible Mistakes
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
 
Mutation Testing and MuJava
Mutation Testing and MuJavaMutation Testing and MuJava
Mutation Testing and MuJava
 
Google test training
Google test trainingGoogle test training
Google test training
 
JUnit 5 - The Next Generation
JUnit 5 - The Next GenerationJUnit 5 - The Next Generation
JUnit 5 - The Next Generation
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With Pytest
 
Unit Testing 101
Unit Testing 101Unit Testing 101
Unit Testing 101
 
Software Testing and the R language
Software Testing and the R languageSoftware Testing and the R language
Software Testing and the R language
 
Assessing Unit Test Quality
Assessing Unit Test QualityAssessing Unit Test Quality
Assessing Unit Test Quality
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
Benefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real WorldBenefit From Unit Testing In The Real World
Benefit From Unit Testing In The Real World
 

Viewers also liked

Software Engineering - RS1
Software Engineering - RS1Software Engineering - RS1
Software Engineering - RS1AtakanAral
 
Programmer testing
Programmer testingProgrammer testing
Programmer testingJoao Pereira
 
Basic Unit Testing with Mockito
Basic Unit Testing with MockitoBasic Unit Testing with Mockito
Basic Unit Testing with MockitoAlexander De Leon
 
Mockito a simple, intuitive mocking framework
Mockito   a simple, intuitive mocking frameworkMockito   a simple, intuitive mocking framework
Mockito a simple, intuitive mocking frameworkPhat VU
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first stepsRenato Primavera
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with MockitoRichard Paul
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testingikhwanhayat
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration TestingDavid Berliner
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 

Viewers also liked (14)

Demystifying git
Demystifying git Demystifying git
Demystifying git
 
Software Engineering - RS1
Software Engineering - RS1Software Engineering - RS1
Software Engineering - RS1
 
Programmer testing
Programmer testingProgrammer testing
Programmer testing
 
Basic Unit Testing with Mockito
Basic Unit Testing with MockitoBasic Unit Testing with Mockito
Basic Unit Testing with Mockito
 
Mockito a simple, intuitive mocking framework
Mockito   a simple, intuitive mocking frameworkMockito   a simple, intuitive mocking framework
Mockito a simple, intuitive mocking framework
 
Using Mockito
Using MockitoUsing Mockito
Using Mockito
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
 
Mockito
MockitoMockito
Mockito
 
JUnit & Mockito, first steps
JUnit & Mockito, first stepsJUnit & Mockito, first steps
JUnit & Mockito, first steps
 
Mocking in Java with Mockito
Mocking in Java with MockitoMocking in Java with Mockito
Mocking in Java with Mockito
 
Understanding Unit Testing
Understanding Unit TestingUnderstanding Unit Testing
Understanding Unit Testing
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
How to Use Slideshare
How to Use SlideshareHow to Use Slideshare
How to Use Slideshare
 

Similar to Software Engineering - RS3

Xp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocksguillaumecarre
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Ukraine
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguestc8093a6
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android ApplicationsRody Middelkoop
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testingpleeps
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitAmr E. Mohamed
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit testEugenio Lentini
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)Thierry Gayet
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And DrupalPeter Arato
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4Billie Berzinskas
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testingalessiopace
 

Similar to Software Engineering - RS3 (20)

Xp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And MocksXp Day 080506 Unit Tests And Mocks
Xp Day 080506 Unit Tests And Mocks
 
Mocking with Mockito
Mocking with MockitoMocking with Mockito
Mocking with Mockito
 
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Testing w-mocks
Testing w-mocksTesting w-mocks
Testing w-mocks
 
Unit testing basic
Unit testing basicUnit testing basic
Unit testing basic
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit testing
Unit testingUnit testing
Unit testing
 
Why test with flex unit
Why test with flex unitWhy test with flex unit
Why test with flex unit
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 
How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 

More from AtakanAral

Subgraph Matching for Resource Allocation in the Federated Cloud Environment
Subgraph Matching for Resource Allocation in the Federated Cloud EnvironmentSubgraph Matching for Resource Allocation in the Federated Cloud Environment
Subgraph Matching for Resource Allocation in the Federated Cloud EnvironmentAtakanAral
 
Quality of Service Channelling for Latency Sensitive Edge Applications
Quality of Service Channelling for Latency Sensitive Edge ApplicationsQuality of Service Channelling for Latency Sensitive Edge Applications
Quality of Service Channelling for Latency Sensitive Edge ApplicationsAtakanAral
 
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...AtakanAral
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...AtakanAral
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...AtakanAral
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...AtakanAral
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...AtakanAral
 
Software Engineering - RS4
Software Engineering - RS4Software Engineering - RS4
Software Engineering - RS4AtakanAral
 
Software Engineering - RS2
Software Engineering - RS2Software Engineering - RS2
Software Engineering - RS2AtakanAral
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]AtakanAral
 
Analysis of Algorithms II - PS5
Analysis of Algorithms II - PS5Analysis of Algorithms II - PS5
Analysis of Algorithms II - PS5AtakanAral
 
Improving Resource Utilization in Cloud using Application Placement Heuristics
Improving Resource Utilization in Cloud using Application Placement HeuristicsImproving Resource Utilization in Cloud using Application Placement Heuristics
Improving Resource Utilization in Cloud using Application Placement HeuristicsAtakanAral
 
Analysis of Algorithms II - PS3
Analysis of Algorithms II - PS3Analysis of Algorithms II - PS3
Analysis of Algorithms II - PS3AtakanAral
 
Analysis of Algorithms II - PS2
Analysis of Algorithms II - PS2Analysis of Algorithms II - PS2
Analysis of Algorithms II - PS2AtakanAral
 
Analysis of Algorithms - 5
Analysis of Algorithms - 5Analysis of Algorithms - 5
Analysis of Algorithms - 5AtakanAral
 
Analysis of Algorithms - 3
Analysis of Algorithms - 3Analysis of Algorithms - 3
Analysis of Algorithms - 3AtakanAral
 
Analysis of Algorithms - 2
Analysis of Algorithms - 2Analysis of Algorithms - 2
Analysis of Algorithms - 2AtakanAral
 
Analysis of Algorithms - 1
Analysis of Algorithms - 1Analysis of Algorithms - 1
Analysis of Algorithms - 1AtakanAral
 
Mobile Multi-domain Search over Structured Web Data
Mobile Multi-domain Search over Structured Web DataMobile Multi-domain Search over Structured Web Data
Mobile Multi-domain Search over Structured Web DataAtakanAral
 

More from AtakanAral (19)

Subgraph Matching for Resource Allocation in the Federated Cloud Environment
Subgraph Matching for Resource Allocation in the Federated Cloud EnvironmentSubgraph Matching for Resource Allocation in the Federated Cloud Environment
Subgraph Matching for Resource Allocation in the Federated Cloud Environment
 
Quality of Service Channelling for Latency Sensitive Edge Applications
Quality of Service Channelling for Latency Sensitive Edge ApplicationsQuality of Service Channelling for Latency Sensitive Edge Applications
Quality of Service Channelling for Latency Sensitive Edge Applications
 
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
Resource Mapping Optimization for Distributed Cloud Services - PhD Thesis Def...
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Progres...
 
Software Engineering - RS4
Software Engineering - RS4Software Engineering - RS4
Software Engineering - RS4
 
Software Engineering - RS2
Software Engineering - RS2Software Engineering - RS2
Software Engineering - RS2
 
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
Modeling and Optimization of Resource Allocation in Cloud [PhD Thesis Proposal]
 
Analysis of Algorithms II - PS5
Analysis of Algorithms II - PS5Analysis of Algorithms II - PS5
Analysis of Algorithms II - PS5
 
Improving Resource Utilization in Cloud using Application Placement Heuristics
Improving Resource Utilization in Cloud using Application Placement HeuristicsImproving Resource Utilization in Cloud using Application Placement Heuristics
Improving Resource Utilization in Cloud using Application Placement Heuristics
 
Analysis of Algorithms II - PS3
Analysis of Algorithms II - PS3Analysis of Algorithms II - PS3
Analysis of Algorithms II - PS3
 
Analysis of Algorithms II - PS2
Analysis of Algorithms II - PS2Analysis of Algorithms II - PS2
Analysis of Algorithms II - PS2
 
Analysis of Algorithms - 5
Analysis of Algorithms - 5Analysis of Algorithms - 5
Analysis of Algorithms - 5
 
Analysis of Algorithms - 3
Analysis of Algorithms - 3Analysis of Algorithms - 3
Analysis of Algorithms - 3
 
Analysis of Algorithms - 2
Analysis of Algorithms - 2Analysis of Algorithms - 2
Analysis of Algorithms - 2
 
Analysis of Algorithms - 1
Analysis of Algorithms - 1Analysis of Algorithms - 1
Analysis of Algorithms - 1
 
Mobile Multi-domain Search over Structured Web Data
Mobile Multi-domain Search over Structured Web DataMobile Multi-domain Search over Structured Web Data
Mobile Multi-domain Search over Structured Web Data
 

Recently uploaded

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfAMB-Review
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfGlobus
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowPeter Caitens
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownloadvrstrong314
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...Alluxio, Inc.
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAlluxio, Inc.
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisNeo4j
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of ProgrammingMatt Welsh
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion Clinic
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 

Recently uploaded (20)

Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 

Software Engineering - RS3

  • 1. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References BLG 411E – Software Engineering Recitation Session 3 Test-Driven Development Atakan Aral, Bilge Süheyla Akkoca 11.11.2014
  • 2. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References Outline 1 Introduction 2 Unit Tests JUnit 3 Auto Tests Cucumber 4 Mock Objects Mockito 5 References
  • 3. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References TDD Definition A software development process. Based on text-first concept in Extreme Programming. Relies on the repetition of a very short development cycle. Also called Red-Greed-Refactor
  • 4. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References TDD Life-cycle 1 Write a test Before implementation 2 Run the test Should fail 3 Write the implementation code Just enough to pass the test Not perfect 4 Run all tests All should pass 5 Refactor Optimize code without introducing new features Should not make any tests fail Should not include new tests 6 Repeat
  • 5. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References TDD Features All about speed: short unit tests (JUnit), imperfect but fast code. Forces us to think before coding. Allows us to develop fast without being afraid to break something. Allows us to refactor with confidence. External dependencies should be mocked (mockito). So that we can test without other parts implemented. So out tests run faster (For instance, a DB connection). This forces us to separate concerns (DB instance can be replaced easily). A note Tools that we will introduce today do not belong to TDD. You can use them with any process.
  • 6. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References TDD Behavior-Driven Development (BDD) An extension to TDD. In TDD, the tests may target class and methods (state) instead of their actual purpose (behaviour). Purpose of the user story is clearly related to the business outcomes. Single notation and ubiquitous language to improve communication (Gherkin language). Scenario’s are used instead of tests to avoid technicalities. Test can be generated automatically (cucumber).
  • 7. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References Unit Testing Definition A white-box testing method for individual units of code. A unit is the smallest testable part of an application. Function in procedural programming Interface, class or method in object-oriented programming. Should be easy to write and fast to execute. Each unit test should be independent of others. Helps to identify problems early and to refactor easily.
  • 8. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References JUnit JUnit is a test framework which uses annotations to identify methods that specify a test. @Test, @Test (expected = Exception.class), @Test(timeout=100), @Before, @After, @BeforeClass, @AfterClass, @Ignore JUnit provides static methods to test for certain conditions. fail, assertTrue, assertFalse, assertEquals, assertNull, assertNotNull, assertSame, assertNotSame
  • 9. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References Test Automation Definition Manual testing usually takes too much time and resources. Tests can be automatically generated from BDD style descriptions. Tests can be fully automated as a part of build process. Watchers can be used to detect changes in the code, recompile if necessary, and run the tests.
  • 10. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References Cucumber Cucumber is a BDD tool that executes plain-text functional descriptions as automated tests. Step definitions in Gherkin (Given, When, Then, And, But) are matched to a piece of code. If the step is matched and the code does not raise an Exception, the step is successful (green). If the step is not matched to any code, the step is pending (yellow). If the step is matched and the code raises an Exception, the step is failed (red).
  • 11. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References Test Doubles A Vocabulary Dummy No implementation, just to fill the parameter list Stub Minimal implementation, returns hard-coded values Spy Similar to stub, also records invoked members Fake Have a simple implementation with some shortcuts, e.g. in-memory DB instead of real one Mock Dynamically created by a mock library, can be configured to return values, expect particular members to be invoked, etc.
  • 12. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References Test Doubles Stub vs. Mock public void t e s tOr d e rSe n d sMa i l I fUn f i l l e d ( ) { / / Stub Order order = new Order (TALISKER, 51) ; Mai lServiceStub mai ler = new Mai lServiceStub ( ) ; order . setMai ler ( mai ler ) ; order . f i l l ( warehouse ) ; asser tEquals (1 , mai ler . numberSent ( ) ) ; } public void t e s tOr d e rSe n d sMa i l I fUn f i l l e d ( ) { / / Mock Order order = new Order (TALISKER, 51) ; Mock warehouse = mock (Warehouse . class ) ; Mock mai ler = mock ( Mai lService . class ) ; order . setMai ler ( ( Mai lService ) mai ler . proxy ( ) ) ; mai ler . expects ( once ( ) ) . method ( " send " ) ; warehouse . expects ( once ( ) ) . method ( " hasInventory " ) . withAnyArguments ( ) . w i l l ( returnValue ( false ) ) ; order . f i l l ( (Warehouse ) warehouse . proxy ( ) ) ; }
  • 13. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References Mockito Behavior can be defined using when, thenReturn, thenThrow, thenAnswer methods. myClass myMock = mock(myClass.class); when(myMock.myMethod(5)) .thenReturn("five"); Behavior can be verified using verify method. verify(myMock).myMethod(12); verify(myMock).myMethod(anyInt()); verify(myMock) .myMethod(argThat(isValid())); verify(myMock, times(2)).myMethod(any()); verify(myMock, atMost(3)).myMethod(5); verifyNoMoreInteractions(myMock); inOrder.verify(myMock, atLeast(2)) .myMethod(5); inOrder.verify(myMock, times(1)) .myMethod(4);
  • 14. BLG 411E Software Engineering Recitation 3 Introduction Unit Tests JUnit Auto Tests Cucumber Mock Objects Mockito References References and Further Reading http://technologyconversations.com/2014/09/30/ test-driven-development-tdd/ http://technologyconversations.com/2013/12/20/ test-driven-development-tdd-example-walkthrough/ http://dannorth.net/introducing-bdd/ Meszaros, Gerard (2007). xUnit Test Patterns: Refactoring Test Code. Addison-Wesley. ISBN 978-0-13-149505-0. http://msdn.microsoft.com/en-us/magazine/cc163358.aspx http://junit.org/ https://github.com/cucumber/cucumber/wiki https://code.google.com/p/mockito/