[xp2013] Narrow Down What to Test

Zsolt Fabok
Zsolt FabokAgile Coach, team leader
Not sure if I have to check out this problem
Or just wait for the customer feedback
How to Narrow Down What to Test
@ZsoltFabok
http://zsoltfabok.com/
#xp2013
http://xp2013.org/
by
Zsolt Fabok
2013-06-05
@ZsoltFabok
or
#xp2013
Exercise 0: Setup
Download putty.exe if you are using windows:
http://<host>:8080/xp2013/putty.exe
Log in (user, userpass):
ssh user@<host> -p 3022
Create your environment:
$ cd xp2013
$ mkdir <yourname>
$ cp -r arithmetic.expression.evaluator <yourname>
$ cd <yourname>/arithmetic.expression.evaluator
$ ant init
Check the source directory in your browser:
http://<host>:8080/xp2013/<yourname>
“I get paid for code that works, not for tests, so my
philosophy is to test as little as possible to reach a given
level of confidence (I suspect this level of confidence is
high compared to industry standards, but that could just
be hubris). If I don’t typically make a kind of mistake (like
setting the wrong variables in a constructor), I don’t test
for it. I do tend to make sense of test errors, so I’m extra
careful when I have logic with complicated conditionals.
When coding on a team, I modify my strategy to carefully
test code that we, collectively, tend to get wrong.”
Kent Beck - September 10, 2010
quote: http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests/153565#153565
I’d like to [re]start working on this
legacy application
My “where to start” list
#1 Determine which parts of
the code are really used
The good old Standish Group Study
7%
13%
16%19%
45%
Always
Often
Sometimes
Rarely
Never
The goal is to find those features which are
always or often used.
By studying coverage, access logs,
traces, web analytics, heat maps, etc.
Let’s have a look at the coverage
(using instrumented class files):
% cp jetty/cobertura.ser web.ser
% cp uploader/cobertura.ser ant.ser
% ant usage_coverage
usage_coverage:
[cobertura-merge] Cobertura: Loaded information on 12 classes.
[cobertura-merge] Cobertura: Loaded information on 11 classes.
[cobertura-merge] Cobertura: Saved information on 16 classes.
[cobertura-report] Cobertura: Loaded information on 16 classes.
[cobertura-report] Report time: 600ms
BUILD SUCCESSFUL
Total time: 2 seconds
Example #1: overview
Example #2: execution
not even
executed
Example #3: number of execution
.NET wins
FileBasedMetadata (usage)
FileHelper (usage)
Exercise 1: Usage
Run the application:
$ run.sh “4+3”
Turn on data collection:
$ ant instrument
$ vi run.sh
Run the application a couple of times:
$ run.sh “4+3”
Generate report:
$ ant usage_report
#2 Find out which parts of
the code change often
By checking how many times a file has
been committed into VCS:
% ./git_stat.sh
14, VerifierTask.java
13, index.jsp
11, FileBasedUserHome.java
11, FileBasedUser.java
11, FileBasedContentTracker.java
8, IntegrityCheckTask.java
7, MailSender.java
FileBasedMetadata (usage)
FileHelper (usage)
VerifierTask (changes)
index.jsp (changes)
FileBasedUserHome (changes)
Exercise 2: Have a beer (or
tea of coffee) :-)
#3 Determine which part of
the code changes data
Code review
“You have exactly 1 minute to explain to me
what that method does!”
FileBasedMetadata (usage)
FileHelper (usage, review)
VerifierTask (changes)
index.jsp (changes)
FileBasedUserHome (changes, review)
FileBasedContentTracker (review)
Exercise 3: Code Review
Check the code in the reports directory in your
browser:
http://<host>:8080/xp2013/<yourname>/.../target/
reports/src
#4 Determine where the code
is most likely going to fail
(e.g. with static code checkers)
[xp2013] Narrow Down What to Test
PMD is not helpful at the moment,
but good to know about it
[xp2013] Narrow Down What to Test
FileBasedMetadata (usage)
FileHelper (usage, review, bugs)
VerifierTask (changes)
index.jsp (changes)
FileBasedUserHome (changes, review)
FileBasedContentTracker (review, bugs)
HarversterTask (bugs)
FileBasedContentTracker.fsck() (crap4j)
FileBasedContentTracker.gc() (crap4j)
VerifierTask.execute() (crap4j)
Let’s order our list and
we are done!
FileBasedMetadata (usage)
FileHelper (usage, review, bugs)
VerifierTask (changes)
index.jsp (changes)
FileBasedUserHome (changes, review)
FileBasedContentTracker (review, bugs)
HarversterTask (bugs)
FileBasedContentTracker.fsck() (crap4j)
FileBasedContentTracker.gc() (crap4j)
VerifierTask.execute() (crap4j)
Exercise 4: Code Checkers
Check the reports directory in your browser:
http://<host>/xp2013/<yourname>/.../target/reports
Generate reports:
$ ant reports
Now we know where to start, and
now let’s talk about how to start.
Gaining 30% coverage in 2 minutes:
public class CheaterTest {
@Test
public void shouldIncreaseTheCoverage() {
HarvesterTask harvester = new HarvesterTask();
Project project = new Project();
project.setBaseDir(new File("."));
harvester.setProject(project);
harvester.setRepository("../repository");
harvester.setHistory("history");
harvester.setTemplate("templates");
harvester.execute();
}
}
Covered code != Tested code
So, you start with an assertion:
public class FileHelperTest {
@Test
public void shouldReturnTheContentOfAFile() throws IOException {
assertEquals("", FileHelper.getFileContent(null));
}
}
➡ The ‘assertEquals’ makes sure that your test actually
does something
➡ The ‘null’ parameter - along with the
NullPointerException - will show you where to continue
First test case is done:
public class FileHelperTest {
@Test
public void shouldReturnTheContentOfAFile() throws IOException {
File input = File.createTempFile("foo", "bar");
assertEquals("", FileHelper.getFileContent(input));
}
}
➡ Now the test is green, let’s continue with a more
meaningful test case
Now we have two test cases:
public class FileHelperTest {
@Test
public void shouldReturnTheContentOfAFile() throws IOException {
File input = File.createTempFile("foo", "bar");
assertEquals("", FileHelper.getFileContent(input));
}
@Test
public void shouldReturnTheContentOfAFile() throws IOException {
File input = File.createTempFile("foo", "bar");
new FileOutputStream(input).write("something".getBytes());
assertEquals("something", FileHelper.getFileContent(input));
}
}
➡ Test method names remains the same until the body is
filled properly
And we are done (assertion + coverage):
public class FileHelperTest {
private File input;
@Before
public void setUp() throws IOException {
input = File.createTempFile("foo", "bar");
}
@Test
public void shouldReturnAnEmptyStringForAnEmptyFile() throws IOException {
assertEquals("", FileHelper.getFileContent(input));
}
@Test
public void shouldReturnTheContentOfAFile() throws IOException {
setInputFileContent("something");
assertEquals("something", FileHelper.getFileContent(input));
}
private void setInputFileContent(String content) throws IOException {
new FileOutputStream(input).write("something".getBytes());
}
}
Exercise 5: Writing tests
Get test coverage (also runs tests):
$ ant cobertura
Run tests:
$ ant test
If you don’t want to write tests, you can find
examples in this folder:
samples
Well tested code
Well tested code everywhere
What about web applications?
(I’ll use a ruby on rails example, but the principles apply to other frameworks as well)
#2 Find out which parts of the code change
often (a.k.a VCS statistics)
#3 Determine which part of the code
changes data (a.k.a code review)
Points
are just the same.
and
A large variety of tools are available for:
#4 Determine where the code is most likely
going to fail (a.k.a static code checkers)
% gem install rails_best_practices
% rails_best_practices -html .
[xp2013] Narrow Down What to Test
[xp2013] Narrow Down What to Test
Everything is nice and straightforward
until now, but the last remaining point
is tricky:
#1 Determine which parts of the code
are really used (a.k.a. coverage)
We can have coverage data in Ruby on Rails, too:
~/Temp/repos/sample_app % gem install simplecov
~/Temp/repos/sample_app % cat script/rails
#!/usr/bin/env ruby
require 'simplecov'
SimpleCov.start do
add_group "Models", "app/models"
add_group "Controllers", "app/controllers"
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
# rest of the script/rails script
[xp2013] Narrow Down What to Test
There is only one problem: the application
must be stopped in order to get the report,
which is not really efficient and user friendly.
Fortunately, we can use a metric called
‘funnel’:
[xp2013] Narrow Down What to Test
1. This is a huge lost in visitors,
would be good to know why.
2. Users visit this page more
often than the other page.
Slides: http://zsoltfabok.com/speaking/
Code: https://github.com/ZsoltFabok/
arithmetic.expression.evaluator/tree/xp2013/
Thank you very much for your attention!
http://zsoltfabok.com/ @ZsoltFabok
1 of 60

Recommended

Rx for Android & iOS by Harin Trivedi by
Rx for Android & iOS  by Harin TrivediRx for Android & iOS  by Harin Trivedi
Rx for Android & iOS by Harin Trivediharintrivedi
299 views28 slides
Enhanced Web Service Testing: A Better Mock Structure by
Enhanced Web Service Testing: A Better Mock StructureEnhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock StructureSalesforce Developers
1.9K views44 slides
Taking advantage of Prometheus relabeling by
Taking advantage of Prometheus relabelingTaking advantage of Prometheus relabeling
Taking advantage of Prometheus relabelingJulien Pivotto
21.6K views43 slides
Functional tests for dummies by
Functional tests for dummiesFunctional tests for dummies
Functional tests for dummiescpsitgmbh
2.8K views17 slides
Unit tests for dummies by
Unit tests for dummiesUnit tests for dummies
Unit tests for dummiescpsitgmbh
2.3K views21 slides
Functional tests with TYPO3 by
Functional tests with TYPO3Functional tests with TYPO3
Functional tests with TYPO3cpsitgmbh
3.5K views25 slides

More Related Content

What's hot

Integration test framework by
Integration test frameworkIntegration test framework
Integration test frameworkIlya Medvedev
52 views30 slides
Client server part 12 by
Client server part 12Client server part 12
Client server part 12fadlihulopi
64 views5 slides
React mit TypeScript – eine glückliche Ehe by
React mit TypeScript – eine glückliche EheReact mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche Eheinovex GmbH
367 views48 slides
Building unit tests correctly by
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctlyDror Helper
1.4K views40 slides
Unit testing patterns for concurrent code by
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent codeDror Helper
3K views50 slides
Discussing Errors in Unity3D's Open-Source Components by
Discussing Errors in Unity3D's Open-Source ComponentsDiscussing Errors in Unity3D's Open-Source Components
Discussing Errors in Unity3D's Open-Source ComponentsPVS-Studio
101 views8 slides

What's hot(20)

Client server part 12 by fadlihulopi
Client server part 12Client server part 12
Client server part 12
fadlihulopi64 views
React mit TypeScript – eine glückliche Ehe by inovex GmbH
React mit TypeScript – eine glückliche EheReact mit TypeScript – eine glückliche Ehe
React mit TypeScript – eine glückliche Ehe
inovex GmbH367 views
Building unit tests correctly by Dror Helper
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
Dror Helper1.4K views
Unit testing patterns for concurrent code by Dror Helper
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
Dror Helper3K views
Discussing Errors in Unity3D's Open-Source Components by PVS-Studio
Discussing Errors in Unity3D's Open-Source ComponentsDiscussing Errors in Unity3D's Open-Source Components
Discussing Errors in Unity3D's Open-Source Components
PVS-Studio101 views
Interaction testing using mock objects by Lim Chanmann
Interaction testing using mock objectsInteraction testing using mock objects
Interaction testing using mock objects
Lim Chanmann1.1K views
C Sharp Tutorial : C Sharp Exception by Courseing Online
C Sharp Tutorial : C Sharp ExceptionC Sharp Tutorial : C Sharp Exception
C Sharp Tutorial : C Sharp Exception
Courseing Online118 views
Laporan tugas network programming by RahmatHamdani2
Laporan tugas network programmingLaporan tugas network programming
Laporan tugas network programming
RahmatHamdani256 views
Programming with ZooKeeper - A basic tutorial by Jeff Smith
Programming with ZooKeeper - A basic tutorialProgramming with ZooKeeper - A basic tutorial
Programming with ZooKeeper - A basic tutorial
Jeff Smith1.5K views
maxbox starter72 multilanguage coding by Max Kleiner
maxbox starter72 multilanguage codingmaxbox starter72 multilanguage coding
maxbox starter72 multilanguage coding
Max Kleiner102 views
Learning Java 4 – Swing, SQL, and Security API by caswenson
Learning Java 4 – Swing, SQL, and Security APILearning Java 4 – Swing, SQL, and Security API
Learning Java 4 – Swing, SQL, and Security API
caswenson1.7K views
SPARQLing cocktails by Timea Turdean
SPARQLing cocktailsSPARQLing cocktails
SPARQLing cocktails
Timea Turdean10.5K views
Legacy Code Kata v3.0 by William Munn
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0
William Munn2.5K views
201913046 wahyu septiansyah network programing by wahyuseptiansyah
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
wahyuseptiansyah64 views
Cassandra Summit EU 2014 - Testing Cassandra Applications by Christopher Batey
Cassandra Summit EU 2014 - Testing Cassandra ApplicationsCassandra Summit EU 2014 - Testing Cassandra Applications
Cassandra Summit EU 2014 - Testing Cassandra Applications
Christopher Batey2.6K views
Analysis of merge requests in GitLab using PVS-Studio for C# by Andrey Karpov
Analysis of merge requests in GitLab using PVS-Studio for C#Analysis of merge requests in GitLab using PVS-Studio for C#
Analysis of merge requests in GitLab using PVS-Studio for C#
Andrey Karpov41 views
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk by Red Hat Developers
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech TalkHacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Red Hat Developers4.5K views

Similar to [xp2013] Narrow Down What to Test

How to test infrastructure code: automated testing for Terraform, Kubernetes,... by
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...Yevgeniy Brikman
33.8K views200 slides
Analysis of bugs in Orchard CMS by
Analysis of bugs in Orchard CMSAnalysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMSPVS-Studio
24 views11 slides
Testing in Craft CMS by
Testing in Craft CMSTesting in Craft CMS
Testing in Craft CMSJustinHolt20
493 views51 slides
Monitoring using Prometheus and Grafana by
Monitoring using Prometheus and GrafanaMonitoring using Prometheus and Grafana
Monitoring using Prometheus and GrafanaArvind Kumar G.S
3.6K views25 slides
Porting Rails Apps to High Availability Systems by
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability SystemsMarcelo Pinheiro
4.5K views52 slides
Intro to PHP Testing by
Intro to PHP TestingIntro to PHP Testing
Intro to PHP TestingRan Mizrahi
4.9K views34 slides

Similar to [xp2013] Narrow Down What to Test(20)

How to test infrastructure code: automated testing for Terraform, Kubernetes,... by Yevgeniy Brikman
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
Yevgeniy Brikman33.8K views
Analysis of bugs in Orchard CMS by PVS-Studio
Analysis of bugs in Orchard CMSAnalysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMS
PVS-Studio24 views
Testing in Craft CMS by JustinHolt20
Testing in Craft CMSTesting in Craft CMS
Testing in Craft CMS
JustinHolt20493 views
Monitoring using Prometheus and Grafana by Arvind Kumar G.S
Monitoring using Prometheus and GrafanaMonitoring using Prometheus and Grafana
Monitoring using Prometheus and Grafana
Arvind Kumar G.S3.6K views
Porting Rails Apps to High Availability Systems by Marcelo Pinheiro
Porting Rails Apps to High Availability SystemsPorting Rails Apps to High Availability Systems
Porting Rails Apps to High Availability Systems
Marcelo Pinheiro4.5K views
Intro to PHP Testing by Ran Mizrahi
Intro to PHP TestingIntro to PHP Testing
Intro to PHP Testing
Ran Mizrahi4.9K views
Bring the fun back to java by ciklum_ods
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods640 views
Exploit Frameworks by phanleson
Exploit FrameworksExploit Frameworks
Exploit Frameworks
phanleson1.9K views
Planning For An Effective Storage Solution by Tiffany Rose
Planning For An Effective Storage SolutionPlanning For An Effective Storage Solution
Planning For An Effective Storage Solution
Tiffany Rose3 views
ScalaUA - distage: Staged Dependency Injection by 7mind
ScalaUA - distage: Staged Dependency InjectionScalaUA - distage: Staged Dependency Injection
ScalaUA - distage: Staged Dependency Injection
7mind1.4K views
Resilience Testing by Ran Levy
Resilience Testing Resilience Testing
Resilience Testing
Ran Levy307 views
Watir Presentation Sumanth Krishna. A by Sumanth krishna
Watir Presentation   Sumanth Krishna. AWatir Presentation   Sumanth Krishna. A
Watir Presentation Sumanth Krishna. A
Sumanth krishna2.1K views
Introduction to PowerShell by Boulos Dib
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
Boulos Dib2.6K views
JavaScript - Chapter 15 - Debugging Techniques by WebStackAcademy
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy778 views
Pragmatic Parallels: Java and JavaScript by davejohnson
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson1.2K views
Testing the frontend by Heiko Hardt
Testing the frontendTesting the frontend
Testing the frontend
Heiko Hardt284 views
Workshop quality assurance for php projects tek12 by Michelangelo van Dam
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
We continue checking Microsoft projects: analysis of PowerShell by PVS-Studio
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
PVS-Studio172 views

More from Zsolt Fabok

Kanban visualisation by
Kanban visualisationKanban visualisation
Kanban visualisationZsolt Fabok
1.8K views33 slides
[LKUK13] I Broke the WIP Limit Twice, and I'm Still on the Team by
[LKUK13] I Broke the WIP Limit Twice, and I'm Still on the Team[LKUK13] I Broke the WIP Limit Twice, and I'm Still on the Team
[LKUK13] I Broke the WIP Limit Twice, and I'm Still on the TeamZsolt Fabok
763 views61 slides
[OOP 2014] Social Sciences Make a Difference by
[OOP 2014] Social Sciences Make a Difference[OOP 2014] Social Sciences Make a Difference
[OOP 2014] Social Sciences Make a DifferenceZsolt Fabok
514 views18 slides
[Agile Adria Croatia 2014] The Road to a Fairly Predictable System by
[Agile Adria Croatia 2014] The Road to a Fairly Predictable System[Agile Adria Croatia 2014] The Road to a Fairly Predictable System
[Agile Adria Croatia 2014] The Road to a Fairly Predictable SystemZsolt Fabok
811 views22 slides
Introduction to Software Development by
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software DevelopmentZsolt Fabok
648 views15 slides
Philosophies of Building the Workplace by
Philosophies of Building the WorkplacePhilosophies of Building the Workplace
Philosophies of Building the WorkplaceZsolt Fabok
1.1K views151 slides

More from Zsolt Fabok(20)

Kanban visualisation by Zsolt Fabok
Kanban visualisationKanban visualisation
Kanban visualisation
Zsolt Fabok1.8K views
[LKUK13] I Broke the WIP Limit Twice, and I'm Still on the Team by Zsolt Fabok
[LKUK13] I Broke the WIP Limit Twice, and I'm Still on the Team[LKUK13] I Broke the WIP Limit Twice, and I'm Still on the Team
[LKUK13] I Broke the WIP Limit Twice, and I'm Still on the Team
Zsolt Fabok763 views
[OOP 2014] Social Sciences Make a Difference by Zsolt Fabok
[OOP 2014] Social Sciences Make a Difference[OOP 2014] Social Sciences Make a Difference
[OOP 2014] Social Sciences Make a Difference
Zsolt Fabok514 views
[Agile Adria Croatia 2014] The Road to a Fairly Predictable System by Zsolt Fabok
[Agile Adria Croatia 2014] The Road to a Fairly Predictable System[Agile Adria Croatia 2014] The Road to a Fairly Predictable System
[Agile Adria Croatia 2014] The Road to a Fairly Predictable System
Zsolt Fabok811 views
Introduction to Software Development by Zsolt Fabok
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
Zsolt Fabok648 views
Philosophies of Building the Workplace by Zsolt Fabok
Philosophies of Building the WorkplacePhilosophies of Building the Workplace
Philosophies of Building the Workplace
Zsolt Fabok1.1K views
Agile, Lean UX is Coming by Zsolt Fabok
Agile, Lean UX is ComingAgile, Lean UX is Coming
Agile, Lean UX is Coming
Zsolt Fabok1.8K views
The Road to a Fairly Predictable System by Zsolt Fabok
The Road to a Fairly Predictable SystemThe Road to a Fairly Predictable System
The Road to a Fairly Predictable System
Zsolt Fabok691 views
Measure and Manage Flow in Practice by Zsolt Fabok
Measure and Manage Flow in PracticeMeasure and Manage Flow in Practice
Measure and Manage Flow in Practice
Zsolt Fabok1.6K views
Narrow Down What to Test by Zsolt Fabok
Narrow Down What to TestNarrow Down What to Test
Narrow Down What to Test
Zsolt Fabok2.3K views
Achieving Maintenance Stabilisation with Agile, Kanban and Lean Thinking by Zsolt Fabok
Achieving Maintenance Stabilisation with Agile, Kanban and Lean ThinkingAchieving Maintenance Stabilisation with Agile, Kanban and Lean Thinking
Achieving Maintenance Stabilisation with Agile, Kanban and Lean Thinking
Zsolt Fabok749 views
The Groundhog Day of a Team Leader by Zsolt Fabok
The Groundhog Day of a Team LeaderThe Groundhog Day of a Team Leader
The Groundhog Day of a Team Leader
Zsolt Fabok1.9K views
Bp Meetup - Achieving Maintenance Stabilisation with Agile, Kanban and Lean T... by Zsolt Fabok
Bp Meetup - Achieving Maintenance Stabilisation with Agile, Kanban and Lean T...Bp Meetup - Achieving Maintenance Stabilisation with Agile, Kanban and Lean T...
Bp Meetup - Achieving Maintenance Stabilisation with Agile, Kanban and Lean T...
Zsolt Fabok773 views
Targu Mures - Behind the Curtain: The Agile/Lean Way of Working by Zsolt Fabok
Targu Mures - Behind the Curtain: The Agile/Lean Way of WorkingTargu Mures - Behind the Curtain: The Agile/Lean Way of Working
Targu Mures - Behind the Curtain: The Agile/Lean Way of Working
Zsolt Fabok908 views
Targu Mures - Measure and Manage Flow in Practice by Zsolt Fabok
Targu Mures - Measure and Manage Flow in PracticeTargu Mures - Measure and Manage Flow in Practice
Targu Mures - Measure and Manage Flow in Practice
Zsolt Fabok1.1K views
ACCU2012 - The Groundhog Day of a Team Leader by Zsolt Fabok
ACCU2012 - The Groundhog Day of a Team LeaderACCU2012 - The Groundhog Day of a Team Leader
ACCU2012 - The Groundhog Day of a Team Leader
Zsolt Fabok965 views
Achieving Maintenance Stabilisation with Agile, Kanban and Lean Thinking by Zsolt Fabok
Achieving Maintenance Stabilisation with Agile, Kanban and Lean ThinkingAchieving Maintenance Stabilisation with Agile, Kanban and Lean Thinking
Achieving Maintenance Stabilisation with Agile, Kanban and Lean Thinking
Zsolt Fabok901 views
SPSE2012 - Measure and Manage Flow in Practice by Zsolt Fabok
SPSE2012 - Measure and Manage Flow in PracticeSPSE2012 - Measure and Manage Flow in Practice
SPSE2012 - Measure and Manage Flow in Practice
Zsolt Fabok1K views
Don't Fear Change, Let Change Fear You by Zsolt Fabok
Don't Fear Change, Let Change Fear YouDon't Fear Change, Let Change Fear You
Don't Fear Change, Let Change Fear You
Zsolt Fabok1.2K views
The Difficult Life of a Lean Team Leader by Zsolt Fabok
The Difficult Life of a Lean Team LeaderThe Difficult Life of a Lean Team Leader
The Difficult Life of a Lean Team Leader
Zsolt Fabok1.3K views

Recently uploaded

University of Borås-full talk-2023-12-09.pptx by
University of Borås-full talk-2023-12-09.pptxUniversity of Borås-full talk-2023-12-09.pptx
University of Borås-full talk-2023-12-09.pptxMahdi_Fahmideh
13 views51 slides
Techstack Ltd at Slush 2023, Ukrainian delegation by
Techstack Ltd at Slush 2023, Ukrainian delegationTechstack Ltd at Slush 2023, Ukrainian delegation
Techstack Ltd at Slush 2023, Ukrainian delegationViktoriiaOpanasenko
7 views4 slides
Top-5-production-devconMunich-2023-v2.pptx by
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptxTier1 app
9 views42 slides
Transport Management System - Shipment & Container Tracking by
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container TrackingFreightoscope
6 views3 slides
tecnologia18.docx by
tecnologia18.docxtecnologia18.docx
tecnologia18.docxnosi6702
6 views5 slides
Ports-and-Adapters Architecture for Embedded HMI by
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMIBurkhard Stubert
37 views19 slides

Recently uploaded(20)

University of Borås-full talk-2023-12-09.pptx by Mahdi_Fahmideh
University of Borås-full talk-2023-12-09.pptxUniversity of Borås-full talk-2023-12-09.pptx
University of Borås-full talk-2023-12-09.pptx
Mahdi_Fahmideh13 views
Top-5-production-devconMunich-2023-v2.pptx by Tier1 app
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
Tier1 app9 views
Transport Management System - Shipment & Container Tracking by Freightoscope
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container Tracking
Freightoscope 6 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67026 views
Ports-and-Adapters Architecture for Embedded HMI by Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
Burkhard Stubert37 views
Understanding HTML terminology by artembondar5
Understanding HTML terminologyUnderstanding HTML terminology
Understanding HTML terminology
artembondar59 views
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile... by Stefan Wolpers
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
Stefan Wolpers49 views
Electronic AWB - Electronic Air Waybill by Freightoscope
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill
Freightoscope 7 views
How to build dyanmic dashboards and ensure they always work by Wiiisdom
How to build dyanmic dashboards and ensure they always workHow to build dyanmic dashboards and ensure they always work
How to build dyanmic dashboards and ensure they always work
Wiiisdom18 views
predicting-m3-devopsconMunich-2023.pptx by Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app10 views

[xp2013] Narrow Down What to Test

  • 1. Not sure if I have to check out this problem Or just wait for the customer feedback How to Narrow Down What to Test @ZsoltFabok http://zsoltfabok.com/ #xp2013 http://xp2013.org/ by Zsolt Fabok 2013-06-05
  • 4. Download putty.exe if you are using windows: http://<host>:8080/xp2013/putty.exe Log in (user, userpass): ssh user@<host> -p 3022 Create your environment: $ cd xp2013 $ mkdir <yourname> $ cp -r arithmetic.expression.evaluator <yourname> $ cd <yourname>/arithmetic.expression.evaluator $ ant init
  • 5. Check the source directory in your browser: http://<host>:8080/xp2013/<yourname>
  • 6. “I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence (I suspect this level of confidence is high compared to industry standards, but that could just be hubris). If I don’t typically make a kind of mistake (like setting the wrong variables in a constructor), I don’t test for it. I do tend to make sense of test errors, so I’m extra careful when I have logic with complicated conditionals. When coding on a team, I modify my strategy to carefully test code that we, collectively, tend to get wrong.” Kent Beck - September 10, 2010 quote: http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests/153565#153565
  • 7. I’d like to [re]start working on this legacy application
  • 8. My “where to start” list
  • 9. #1 Determine which parts of the code are really used
  • 10. The good old Standish Group Study 7% 13% 16%19% 45% Always Often Sometimes Rarely Never
  • 11. The goal is to find those features which are always or often used. By studying coverage, access logs, traces, web analytics, heat maps, etc.
  • 12. Let’s have a look at the coverage (using instrumented class files): % cp jetty/cobertura.ser web.ser % cp uploader/cobertura.ser ant.ser % ant usage_coverage usage_coverage: [cobertura-merge] Cobertura: Loaded information on 12 classes. [cobertura-merge] Cobertura: Loaded information on 11 classes. [cobertura-merge] Cobertura: Saved information on 16 classes. [cobertura-report] Cobertura: Loaded information on 16 classes. [cobertura-report] Report time: 600ms BUILD SUCCESSFUL Total time: 2 seconds
  • 14. Example #2: execution not even executed
  • 15. Example #3: number of execution .NET wins
  • 18. Run the application: $ run.sh “4+3” Turn on data collection: $ ant instrument $ vi run.sh Run the application a couple of times: $ run.sh “4+3” Generate report: $ ant usage_report
  • 19. #2 Find out which parts of the code change often
  • 20. By checking how many times a file has been committed into VCS: % ./git_stat.sh 14, VerifierTask.java 13, index.jsp 11, FileBasedUserHome.java 11, FileBasedUser.java 11, FileBasedContentTracker.java 8, IntegrityCheckTask.java 7, MailSender.java
  • 21. FileBasedMetadata (usage) FileHelper (usage) VerifierTask (changes) index.jsp (changes) FileBasedUserHome (changes)
  • 22. Exercise 2: Have a beer (or tea of coffee) :-)
  • 23. #3 Determine which part of the code changes data
  • 24. Code review “You have exactly 1 minute to explain to me what that method does!”
  • 25. FileBasedMetadata (usage) FileHelper (usage, review) VerifierTask (changes) index.jsp (changes) FileBasedUserHome (changes, review) FileBasedContentTracker (review)
  • 27. Check the code in the reports directory in your browser: http://<host>:8080/xp2013/<yourname>/.../target/ reports/src
  • 28. #4 Determine where the code is most likely going to fail (e.g. with static code checkers)
  • 30. PMD is not helpful at the moment, but good to know about it
  • 32. FileBasedMetadata (usage) FileHelper (usage, review, bugs) VerifierTask (changes) index.jsp (changes) FileBasedUserHome (changes, review) FileBasedContentTracker (review, bugs) HarversterTask (bugs) FileBasedContentTracker.fsck() (crap4j) FileBasedContentTracker.gc() (crap4j) VerifierTask.execute() (crap4j)
  • 33. Let’s order our list and we are done!
  • 34. FileBasedMetadata (usage) FileHelper (usage, review, bugs) VerifierTask (changes) index.jsp (changes) FileBasedUserHome (changes, review) FileBasedContentTracker (review, bugs) HarversterTask (bugs) FileBasedContentTracker.fsck() (crap4j) FileBasedContentTracker.gc() (crap4j) VerifierTask.execute() (crap4j)
  • 35. Exercise 4: Code Checkers
  • 36. Check the reports directory in your browser: http://<host>/xp2013/<yourname>/.../target/reports Generate reports: $ ant reports
  • 37. Now we know where to start, and now let’s talk about how to start.
  • 38. Gaining 30% coverage in 2 minutes: public class CheaterTest { @Test public void shouldIncreaseTheCoverage() { HarvesterTask harvester = new HarvesterTask(); Project project = new Project(); project.setBaseDir(new File(".")); harvester.setProject(project); harvester.setRepository("../repository"); harvester.setHistory("history"); harvester.setTemplate("templates"); harvester.execute(); } } Covered code != Tested code
  • 39. So, you start with an assertion: public class FileHelperTest { @Test public void shouldReturnTheContentOfAFile() throws IOException { assertEquals("", FileHelper.getFileContent(null)); } } ➡ The ‘assertEquals’ makes sure that your test actually does something ➡ The ‘null’ parameter - along with the NullPointerException - will show you where to continue
  • 40. First test case is done: public class FileHelperTest { @Test public void shouldReturnTheContentOfAFile() throws IOException { File input = File.createTempFile("foo", "bar"); assertEquals("", FileHelper.getFileContent(input)); } } ➡ Now the test is green, let’s continue with a more meaningful test case
  • 41. Now we have two test cases: public class FileHelperTest { @Test public void shouldReturnTheContentOfAFile() throws IOException { File input = File.createTempFile("foo", "bar"); assertEquals("", FileHelper.getFileContent(input)); } @Test public void shouldReturnTheContentOfAFile() throws IOException { File input = File.createTempFile("foo", "bar"); new FileOutputStream(input).write("something".getBytes()); assertEquals("something", FileHelper.getFileContent(input)); } } ➡ Test method names remains the same until the body is filled properly
  • 42. And we are done (assertion + coverage): public class FileHelperTest { private File input; @Before public void setUp() throws IOException { input = File.createTempFile("foo", "bar"); } @Test public void shouldReturnAnEmptyStringForAnEmptyFile() throws IOException { assertEquals("", FileHelper.getFileContent(input)); } @Test public void shouldReturnTheContentOfAFile() throws IOException { setInputFileContent("something"); assertEquals("something", FileHelper.getFileContent(input)); } private void setInputFileContent(String content) throws IOException { new FileOutputStream(input).write("something".getBytes()); } }
  • 44. Get test coverage (also runs tests): $ ant cobertura Run tests: $ ant test If you don’t want to write tests, you can find examples in this folder: samples
  • 45. Well tested code Well tested code everywhere
  • 46. What about web applications? (I’ll use a ruby on rails example, but the principles apply to other frameworks as well)
  • 47. #2 Find out which parts of the code change often (a.k.a VCS statistics) #3 Determine which part of the code changes data (a.k.a code review) Points are just the same. and
  • 48. A large variety of tools are available for: #4 Determine where the code is most likely going to fail (a.k.a static code checkers)
  • 49. % gem install rails_best_practices % rails_best_practices -html .
  • 52. Everything is nice and straightforward until now, but the last remaining point is tricky: #1 Determine which parts of the code are really used (a.k.a. coverage)
  • 53. We can have coverage data in Ruby on Rails, too: ~/Temp/repos/sample_app % gem install simplecov ~/Temp/repos/sample_app % cat script/rails #!/usr/bin/env ruby require 'simplecov' SimpleCov.start do add_group "Models", "app/models" add_group "Controllers", "app/controllers" end APP_PATH = File.expand_path('../../config/application', __FILE__) # rest of the script/rails script
  • 55. There is only one problem: the application must be stopped in order to get the report, which is not really efficient and user friendly.
  • 56. Fortunately, we can use a metric called ‘funnel’:
  • 58. 1. This is a huge lost in visitors, would be good to know why. 2. Users visit this page more often than the other page.
  • 60. Thank you very much for your attention! http://zsoltfabok.com/ @ZsoltFabok