SlideShare une entreprise Scribd logo
1  sur  25
Advanced testing techniques 
When assertThat(you).understandUnitTesting() fails 
23 October 2014 
Martin Škurla, Equities IT
Speaker’s Bio 
• Ing. Martin Škurla 
• Certifications 
• Sun Certified Programmer for the Java 2 Platform, Standard Edition 6.0 
• Oracle Certified Professional, Java EE 5 Web Component Developer 
• Open Source Committer 
• Gephi (GSoC 2010), NetBeans (NetCAT), Abego Tree Layout, AST Visualizer, 
Tyrus 
• Conference/JUG Speaker 
• Fosdem, CZJUG, GeeCON 
• Technical Reviewer 
• CPress, Grada, Manning 
• Previous work experience 
• Sors Technology, ESET, Celum, Atlassian 
• Currently 
• PSEC at Barclays 
2 | Advanced testing techniques | 23 October 2014 
COPYRIGHT © Copyright Barclays Bank PLC, 2014 (all rights reserved).
“More than the act of testing, the act of designing tests is one of the 
best bug preventers known. The thinking that must be done to create 
a useful test can discover and eliminate bugs before they are coded – 
indeed, test-design thinking can discover and eliminate bugs at every 
stage in the creation of software, from conception to specification, to 
design, coding and the rest.” [1] 
3 | Advanced testing techniques | 23 October 2014 
Boris Beizer 
[1] Software Testing Techniques, Creating a Software Engineering Culture by Karl Eugene Wiegers, ISBN: 0932633331 , Page: 211
Agenda 
• Test face-lifting 
• naming conventions 
• logical grouping 
• test code smells and “refactoring patterns” 
• bad practices and pitfalls 
• Custom assertions 
• Declarative and Data driven testing 
• Advanced techniques 
• TestNG framework integration 
• concurrent test execution 
• Results (code reduction, number of tests, execution time) 
4 | Advanced testing techniques | 23 October 2014
Naming conventions 
• The most important asset of a unit test is readability. 
• We try to achieve “readable tests” 
• readable vs. understandable tests 
• Test method naming conventions: 
• testNameOfTheMethod() antipattern 
• method name should contain 3 parts: behavior being tested, inputs and outputs 
• e.g. attrUsedInRules_ShouldNotBeAbleToRemove(), 
removingAttrUsedInRules_ShouldThrowIllegalArgumentException(), 
ruleEqualsAndHashCodeMethods_ShouldBeCorrectlyImplemented(), 
getAttrVal_ShouldThrowExceptionWhenAmbiguityHappens() 
• Test lifecycle method naming conventions: 
• setUp() & tearDown() antipatterns 
• e.g. @BeforeMethod public void rulesInit() {…} 
5 | Advanced testing techniques | 23 October 2014
Logical grouping 
• Don’t put all test code related to single class/method always into the 
same test class. 
• NameOfClassTest antipattern 
• it doesn’t scale for anything but trivial examples 
• Instead, you should group tests logically. 
• AE has attributes, attribute groups, cross rule validation, distinct rules, matching 
expressions, meta rules, querying API, rule ambiguities handling, rule precedence, 
target expressions, transactional behavior 
• e.g. AttrManipulationTest, AttributeEngineTest, AttrGroupTest, 
CrossRuleValidationTest, DistinctRuleTest, 
GettingAttrsRulesAndValsAPITest, MatchingAttrExpressionsTest, 
MetaRuleManipulationTest, MetaRulesTest, RuleAmbiguitiesTest, 
RuleManipulationTest, RuleMatchValsTest, RulePrecedenceTest, 
TargetAttrExpressionsTest, TransactionalBehaviorTest 
6 | Advanced testing techniques | 23 October 2014
Test code smells and “refactoring patterns” 
• Conditions 
• introducing multiple test execution paths is bad 
• => multiple tests, JUnit assumptions, TestNG SkipException 
• Loops 
• introducing multiple test cases into a single test is bad 
• => parameterized testing, more powerful (custom) assertions 
• Assertions on different objects 
• test should only assert on a single object: SUT 
• => refactoring to multiple tests 
• Multiple assignments into the same variable 
• reinitializing the SUT is bad 
• => refactoring to multiple tests 
7 | Advanced testing techniques | 23 October 2014
“Yesterday’s best practices is tomorrow’s anti-pattern.” [2] 
8 | Advanced testing techniques | 23 October 2014 
Neal Ford 
[2] GeeCON Prague 2014 Conference, This is water, Opening Keynote
Bad practices 
• Using assertTrue(), assertFalse(), assertEquals() 
• => use custom assertions 
• Sophisticated string assertion description 
• assertEquals(String message, Object expected, Object actual); 
• => use custom assertions 
• Logging and printing into console 
• => remove it 
• Boolean asserted aggregation 
• => rewrite to multiple tests 
• Sophisticated tests 
• GC tests, memory leak tests, latency tests 
• => remove them 
9 | Advanced testing techniques | 23 October 2014
Common pitfalls 
• Removing repetition 
• some level of repetition is actually good 
• => don’t do that 
• Introducing constants 
• test constants should only be introduced if the particular value is not important for test 
• => don’t introduce constants as in normal code 
• SUT initialization in @BeforeMethod 
• not conforming to arrange-act-assert 
• not directly obvious how SUT is initialized 
• introduces mutability (stay tuned) 
• => don’t initialize SUT in @BeforeMethod if not necessary 
• Reusing SUT 
• you might be relying on already modified state 
• => never reuse already used SUT 
10 | Advanced testing techniques | 23 October 2014
Agenda 
• Test face-lifting 
• naming conventions 
• logical grouping 
• test code smells and “refactoring patterns” 
• bad practices and pitfalls 
• Custom assertions 
• Declarative and Data driven testing 
• Advanced techniques 
• TestNG framework integration 
• concurrent test execution 
• Results (code reduction, number of tests, execution time) 
11 | Advanced testing techniques | 23 October 2014
Custom assertions 
• Because of readability 
• assertThatAttr(“T1”).hasDescription(“…”); 
• Very useful when API is leaking implementation details 
• e.g. returning complicated data structures 
• assertThatUnsuppressedRules(rules).containRulesOnLines(1, 2); 
assertThatSuppressedRules(rules).isNull(); 
• Very powerful when custom assertions reuse other custom assertions 
• assertThatException(e).forRuleOnLine(1).hasDependentCount(1) 
.forRuleOnLine(2).hasDependentCount(2); 
• Think twice before adding custom assertions. 
12 | Advanced testing techniques | 23 October 2014
Agenda 
• Test face-lifting 
• naming conventions 
• logical grouping 
• test code smells and “refactoring patterns” 
• bad practices and pitfalls 
• Custom assertions 
• Declarative and Data driven testing 
• Advanced techniques 
• TestNG framework integration 
• concurrent test execution 
• Results (code reduction, number of tests, execution time) 
13 | Advanced testing techniques | 23 October 2014
Declarative and Data driven testing 
• Data driven testing 
• testing the same code, but with different inputs and outputs 
• Declarative testing 
• tests are saying what to do and not how 
@DataProvider private String[][] attrGroupDataProvider() { 
return new String[][] {{“XETRA”, “b111”, “rule2”}};} 
@MatchingAttrDelimiter(“!”) 
@AeColumns(“M1 ! M2 || +M1 || T1 ”) 
@AeRules( {“LSE ! || EUROPE || ”, 
“+EUROPE” ! /a111 || || rule1”) 
@Test(dataProvider= “attrGroupDataProvider” ) 
public void attrGroup_...(String m1, String m2, String expT1) {} 
14 | Advanced testing techniques | 23 October 2014
Agenda 
• Test face-lifting 
• naming conventions 
• logical grouping 
• test code smells and “refactoring patterns” 
• bad practices and pitfalls 
• Custom assertions 
• Declarative and Data driven testing 
• Advanced techniques 
• TestNG framework integration 
• concurrent test execution 
• Results (code reduction, number of tests, execution time) 
15 | Advanced testing techniques | 23 October 2014
TestNG framework integration 
• TestNG listeners 
• for handling declarative testing 
• @AEColumns, @AEFileResources, @AERules, @MatchingAttrDelimiter, 
@MetaAEColumns, @MetaAERules, @TrimOnlyLeadingAndTrailingSpaces 
• listeners should play nicely with data providers 
• listeners should support concurrency 
• But how does it feel like to integrate into TestNG? 
• happiness followed by hacking3 
private static final Set<String> UGLY_HACK = new HashSet<String>(); 
• you have to expect issues 
• internal bugs (Maven surefire plug-in) 
• workarounds (ROCK-581) 
3 “to devise or modify (a computer program), usually skillfully” according to http://dictionary.reference.com/browse/hacking?s=t 
16 | Advanced testing techniques | 23 October 2014
Concurrent test execution 
• The point of adding concurrency into tests was surprisingly not 
performance. 
• the reason was the independence (isolation) 
• Different granularities 
• test suites, test classes, test methods 
• Achievable by removing all unnecessary and guarding the necessary 
shared state. 
• application of thread-safety and functional principles 
• Test framework integration 
• solid understanding of the testing framework thread model is essential 
• But what to do when thread-safety cannot be achieved? 
• @Test(singleThreaded = true) 
• JVM forking (last resort solution) 
17 | Advanced testing techniques | 23 October 2014
Agenda 
• Test face-lifting 
• naming conventions 
• logical grouping 
• test code smells and “refactoring patterns” 
• bad practices and pitfalls 
• Custom assertions 
• Declarative and Data driven testing 
• Advanced techniques 
• TestNG framework integration 
• concurrent test execution 
• Results (code reduction, number of tests, execution time) 
18 | Advanced testing techniques | 23 October 2014
Results 
• JIRA issues resolved: 
• specifically created: ROCK-349, ROCK-395, ROCK-396, ROCK-397, 
ROCK-481, ROCK-613 
• resolved as a side-effect of refactoring: ROCK-295 
• TestNG workarounds: ROCK-581 
• won’t fix: ROCK-511 
• introduced bug: ROCK-585 
• pending: ROCK-495 
• Testable documentation 
• This is in line with Barclay’s Values including Stewardship 
19 | Advanced testing techniques | 23 October 2014
Results 
40 
35 
30 
25 
20 
15 
10 
600 
550 
500 
450 
400 
350 
300 
250 
200 
150 
100 
Before ROCK-349 ROCK-397 ROCK-396 ROCK-395 ROCK-481 ROCK-613 
Number of tests Execution time (sec) 
65000 
60000 
55000 
50000 
45000 
40000 
35000 
30000 
550 
500 
450 
400 
350 
300 
Before ROCK-349 ROCK-397 ROCK-396 ROCK-395 ROCK-481 ROCK-613 
Test code size (kB) Test resources size (kB) 
• Number of tests: 
• 373.38% 
• Execution time: 
• 42.64% 
• Number of lines: 
• 61.57% 
• Test code size: 
• 63.99% 
• Test resources size: 
• 57.45% 
20 | Advanced testing techniques | 23 October 2014
More on testing libraries, books 
• Links4: 
• http://testng.org/doc/index.html 
• http://code.google.com/p/hamcrest/ 
• http://joel-costigliola.github.io/assertj/ 
• http://code.google.com/p/catch-exception/ 
• http://www.manning.com/koskela2/ 
• http://www.manning.com/osherove2/ 
4 These links were accessed on 23/09/2014. The websites are those of third parties and Barclays is not responsible for any information stated to be obtained 
or derived from these third party sources. 
21 | Advanced testing techniques | 23 October 2014
Q & A 
22 | Advanced testing techniques | 23 October 2014
23 | Advanced testing techniques | 23 October 2014
Thank you for your 
attention
Disclaimer 
CONFLICTS OF INTEREST BARCLAYS IS A FULL SERVICE INVESTMENT BANK. In the normal course of offering investment banking products and services to clients. 
Barclays may act in several capacities (including issuer, market maker, underwriter, distributor, index sponsor, swap counterparty and calculation agent) simultaneously with 
respect to a product, giving rise to potential conflicts of interest which may impact the performance of a product. 
NOT RESEARCH This document is from a Barclays Trading and/or Distribution desk and is not a product of the Barclays Research department. Any views expressed may 
differ from those of Barclays Research. 
BARCLAYS POSITIONS Barclays, its affiliates and associated personnel may at any time acquire, hold or dispose of long or short positions (including hedging and trading 
positions) which may impact the performance of a product. 
FOR INFORMATION ONLY THIS DOCUMENT IS PROVIDED FOR INFORMATION PURPOSES ONLY AND IT IS SUBJECT TO CHANGE. IT IS INDICATIVE ONLY AND IS 
NOT BINDING. 
NO OFFER Barclays is not offering to sell or seeking offers to buy any product or enter into any transaction. Any transaction requires Barclays’ subsequent formal agreement 
which will be subject to internal approvals and binding transaction documents. 
NO LIABILITY Barclays is not responsible for the use made of this document other than the purpose for which it is intended, except to the extent this would be prohibited by 
law or regulation. 
NO ADVICE OBTAIN INDEPENDENT PROFESSIONAL ADVICE BEFORE INVESTING OR TRANSACTING. Barclays is not an advisor and will not provide any advice 
relating to a product. Before making an investment decision, investors should ensure they have sufficient information to ascertain the legal, financial, tax and regulatory 
consequences of an investment to enable them to make an informed investment decision. 
THIRD PARTY INFORMATION Barclays is not responsible for information stated to be obtained or derived from third party sources or statistical services. 
PAST & SIMULATED PAST PERFORMANCE Any past or simulated past performance (including back-testing) contained herein is no indication as to future performance. 
OPINIONS SUBJECT TO CHANGE All opinions and estimates are given as of the date hereof and are subject to change. Barclays is not obliged to inform investors of any 
change to such opinions or estimates. 
NOT FOR RETAIL This document is being directed at persons who are professionals and is not intended for retail customer use. 
IMPORTANT DISCLOSURES For important regional disclosures you must read, click on the link relevant to your region. Please contact your Barclays representative if you 
are unable to access. 
EMEA EMEA Disclosures APAC APAC Disclosures U.S. US Disclosures 
IRS CIRCULAR 230 DISCLOSURE: Barclays does not provide tax advice. Please note that (i) any discussion of US tax matters contained in this communication (including any 
attachments) cannot be used by you for the purpose of avoiding tax penalties; (ii) this communication was written to support the promotion or marketing of the matters addressed 
herein; and (iii) you should seek advice based on your particular circumstances from an independent tax advisor. 
CONFIDENTIAL This document is confidential and no part of it may be reproduced, distributed or transmitted without the prior written permission of Barclays. 
ABOUT BARCLAYS Barclays Bank PLC offers premier investment banking products and services to its clients through Barclays Bank PLC. Barclays Bank PLC is authorised 
by the Prudential Regulation Authority and regulated by the Financial Conduct Authority and the Prudential Regulation Authority and is a member of the London Stock Exchange. 
Barclays Bank PLC is registered in England No. 1026167 with its registered office at 1 Churchill Place, London E14 5HP. 
COPYRIGHT © Copyright Barclays Bank PLC, 2014 (all rights reserved). 
25 | Advanced testing techniques | 23 October 2014

Contenu connexe

Tendances

[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google MockICS
 
Automated Repair of Feature Interaction Failures in Automated Driving Systems
Automated Repair of Feature Interaction Failures in Automated Driving SystemsAutomated Repair of Feature Interaction Failures in Automated Driving Systems
Automated Repair of Feature Interaction Failures in Automated Driving SystemsLionel Briand
 
CppUnit using introduction
CppUnit using introductionCppUnit using introduction
CppUnit using introductionIurii Kyian
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unitliminescence
 
OSGi Applications Testing - André Elia Assad, System Engineer, Cesar
OSGi Applications Testing - André Elia Assad, System Engineer, CesarOSGi Applications Testing - André Elia Assad, System Engineer, Cesar
OSGi Applications Testing - André Elia Assad, System Engineer, Cesarmfrancis
 
xUnit Style Database Testing
xUnit Style Database TestingxUnit Style Database Testing
xUnit Style Database TestingChris Oldwood
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent codeDror Helper
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctlyDror Helper
 
Next Generation Developer Testing: Parameterized Testing
Next Generation Developer Testing: Parameterized TestingNext Generation Developer Testing: Parameterized Testing
Next Generation Developer Testing: Parameterized TestingTao Xie
 
Unit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and HowsUnit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and Howsatesgoral
 
JUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJohn Ferguson Smart Limited
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EEhwilming
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Javaguy_davis
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test frameworkAbner Chih Yi Huang
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Project
 

Tendances (20)

[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
 
Cpp unit
Cpp unit Cpp unit
Cpp unit
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Junit
JunitJunit
Junit
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
TDD Training
TDD TrainingTDD Training
TDD Training
 
Automated Repair of Feature Interaction Failures in Automated Driving Systems
Automated Repair of Feature Interaction Failures in Automated Driving SystemsAutomated Repair of Feature Interaction Failures in Automated Driving Systems
Automated Repair of Feature Interaction Failures in Automated Driving Systems
 
CppUnit using introduction
CppUnit using introductionCppUnit using introduction
CppUnit using introduction
 
Pragmatic unittestingwithj unit
Pragmatic unittestingwithj unitPragmatic unittestingwithj unit
Pragmatic unittestingwithj unit
 
OSGi Applications Testing - André Elia Assad, System Engineer, Cesar
OSGi Applications Testing - André Elia Assad, System Engineer, CesarOSGi Applications Testing - André Elia Assad, System Engineer, Cesar
OSGi Applications Testing - André Elia Assad, System Engineer, Cesar
 
xUnit Style Database Testing
xUnit Style Database TestingxUnit Style Database Testing
xUnit Style Database Testing
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
 
Next Generation Developer Testing: Parameterized Testing
Next Generation Developer Testing: Parameterized TestingNext Generation Developer Testing: Parameterized Testing
Next Generation Developer Testing: Parameterized Testing
 
Unit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and HowsUnit Testing - The Whys, Whens and Hows
Unit Testing - The Whys, Whens and Hows
 
JUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit TestsJUnit Kung Fu: Getting More Out of Your Unit Tests
JUnit Kung Fu: Getting More Out of Your Unit Tests
 
Need(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EENeed(le) for Speed - Effective Unit Testing for Java EE
Need(le) for Speed - Effective Unit Testing for Java EE
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
STAMP Descartes Presentation
STAMP Descartes PresentationSTAMP Descartes Presentation
STAMP Descartes Presentation
 

Similaire à When assertthat(you).understandUnitTesting() fails

Performance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle CoherencePerformance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle Coherencearagozin
 
C++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonC++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonClare Macrae
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsOrtus Solutions, Corp
 
Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Craig Smith
 
May: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and ChallengesMay: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and ChallengesTriTAUG
 
Ivan Pashko - Simplifying test automation with design patterns
Ivan Pashko - Simplifying test automation with design patternsIvan Pashko - Simplifying test automation with design patterns
Ivan Pashko - Simplifying test automation with design patternsIevgenii Katsan
 
SledgehammerToFinebrush_Devnexus_2021
SledgehammerToFinebrush_Devnexus_2021SledgehammerToFinebrush_Devnexus_2021
SledgehammerToFinebrush_Devnexus_2021Shelley Lambert
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Jay Friendly
 
Learning on Deep Learning
Learning on Deep LearningLearning on Deep Learning
Learning on Deep LearningShelley Lambert
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.pptNaviAningi
 
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.pptKKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.pptKiran Kumar SD
 
Test automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsTest automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsSteven Li
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingRam Awadh Prasad, PMP
 
Qt test framework
Qt test frameworkQt test framework
Qt test frameworkICS
 

Similaire à When assertthat(you).understandUnitTesting() fails (20)

Performance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle CoherencePerformance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle Coherence
 
C++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ LondonC++ Testing Techniques Tips and Tricks - C++ London
C++ Testing Techniques Tips and Tricks - C++ London
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
 
Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!Technical Lessons Learned Turning the Agile Dials to Eleven!
Technical Lessons Learned Turning the Agile Dials to Eleven!
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Ch11lect1 ud
Ch11lect1 udCh11lect1 ud
Ch11lect1 ud
 
May: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and ChallengesMay: Automated Developer Testing: Achievements and Challenges
May: Automated Developer Testing: Achievements and Challenges
 
Ivan Pashko - Simplifying test automation with design patterns
Ivan Pashko - Simplifying test automation with design patternsIvan Pashko - Simplifying test automation with design patterns
Ivan Pashko - Simplifying test automation with design patterns
 
SledgehammerToFinebrush_Devnexus_2021
SledgehammerToFinebrush_Devnexus_2021SledgehammerToFinebrush_Devnexus_2021
SledgehammerToFinebrush_Devnexus_2021
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
Unit testing
Unit testingUnit testing
Unit testing
 
Learning on Deep Learning
Learning on Deep LearningLearning on Deep Learning
Learning on Deep Learning
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
190711_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
 
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.pptKKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
KKSD_Testbirds_Selenium_eclipsecon_FINAL_0.ppt
 
Test automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsTest automation principles, terminologies and implementations
Test automation principles, terminologies and implementations
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
 
Qt test framework
Qt test frameworkQt test framework
Qt test framework
 

Plus de Martin Skurla

2024-03-07 - Berne Institute - Neurodiversity Awareness Training.pdf
2024-03-07 - Berne Institute - Neurodiversity Awareness Training.pdf2024-03-07 - Berne Institute - Neurodiversity Awareness Training.pdf
2024-03-07 - Berne Institute - Neurodiversity Awareness Training.pdfMartin Skurla
 
2024-03-03 - Chairwork - Beyond the Basics.pdf
2024-03-03 - Chairwork - Beyond the Basics.pdf2024-03-03 - Chairwork - Beyond the Basics.pdf
2024-03-03 - Chairwork - Beyond the Basics.pdfMartin Skurla
 
2024-02-20 - Berne Institute - Mental Health Familiarisation.pdf
2024-02-20 - Berne Institute - Mental Health Familiarisation.pdf2024-02-20 - Berne Institute - Mental Health Familiarisation.pdf
2024-02-20 - Berne Institute - Mental Health Familiarisation.pdfMartin Skurla
 
Exploring Relational Practice Through Clinical Dilemmas
Exploring Relational Practice Through Clinical DilemmasExploring Relational Practice Through Clinical Dilemmas
Exploring Relational Practice Through Clinical DilemmasMartin Skurla
 
Interpretive Dynamic Transactional Analysis Psychotherapy
Interpretive Dynamic Transactional Analysis PsychotherapyInterpretive Dynamic Transactional Analysis Psychotherapy
Interpretive Dynamic Transactional Analysis PsychotherapyMartin Skurla
 
ESET 3 internship protocol
ESET 3 internship protocolESET 3 internship protocol
ESET 3 internship protocolMartin Skurla
 
Mastering Redecision Therapy
Mastering Redecision TherapyMastering Redecision Therapy
Mastering Redecision TherapyMartin Skurla
 
The Vital Skill of Clinical Assessment
The Vital Skill of Clinical AssessmentThe Vital Skill of Clinical Assessment
The Vital Skill of Clinical AssessmentMartin Skurla
 
Psychotherapy from the clients perspective
Psychotherapy from the clients perspectivePsychotherapy from the clients perspective
Psychotherapy from the clients perspectiveMartin Skurla
 
There's No Place Like Home
There's No Place Like HomeThere's No Place Like Home
There's No Place Like HomeMartin Skurla
 
Advanced Counselling Skills
Advanced Counselling SkillsAdvanced Counselling Skills
Advanced Counselling SkillsMartin Skurla
 
CATA conference 2023.pdf
CATA conference 2023.pdfCATA conference 2023.pdf
CATA conference 2023.pdfMartin Skurla
 
UKATA Conference 2023
UKATA Conference 2023UKATA Conference 2023
UKATA Conference 2023Martin Skurla
 
Applied TA in clinical practice
Applied TA in clinical practiceApplied TA in clinical practice
Applied TA in clinical practiceMartin Skurla
 
Intensive course - Working with therapeutic cards
Intensive course - Working with therapeutic cardsIntensive course - Working with therapeutic cards
Intensive course - Working with therapeutic cardsMartin Skurla
 
Personality Focused Treatment
Personality Focused TreatmentPersonality Focused Treatment
Personality Focused TreatmentMartin Skurla
 
Advanced training in Transanctional analysis
Advanced training in Transanctional analysisAdvanced training in Transanctional analysis
Advanced training in Transanctional analysisMartin Skurla
 
Magdalena internship protocol
Magdalena internship protocolMagdalena internship protocol
Magdalena internship protocolMartin Skurla
 
PPP internship protocol
PPP internship protocolPPP internship protocol
PPP internship protocolMartin Skurla
 

Plus de Martin Skurla (20)

2024-03-07 - Berne Institute - Neurodiversity Awareness Training.pdf
2024-03-07 - Berne Institute - Neurodiversity Awareness Training.pdf2024-03-07 - Berne Institute - Neurodiversity Awareness Training.pdf
2024-03-07 - Berne Institute - Neurodiversity Awareness Training.pdf
 
2024-03-03 - Chairwork - Beyond the Basics.pdf
2024-03-03 - Chairwork - Beyond the Basics.pdf2024-03-03 - Chairwork - Beyond the Basics.pdf
2024-03-03 - Chairwork - Beyond the Basics.pdf
 
2024-02-20 - Berne Institute - Mental Health Familiarisation.pdf
2024-02-20 - Berne Institute - Mental Health Familiarisation.pdf2024-02-20 - Berne Institute - Mental Health Familiarisation.pdf
2024-02-20 - Berne Institute - Mental Health Familiarisation.pdf
 
Exploring Relational Practice Through Clinical Dilemmas
Exploring Relational Practice Through Clinical DilemmasExploring Relational Practice Through Clinical Dilemmas
Exploring Relational Practice Through Clinical Dilemmas
 
Interpretive Dynamic Transactional Analysis Psychotherapy
Interpretive Dynamic Transactional Analysis PsychotherapyInterpretive Dynamic Transactional Analysis Psychotherapy
Interpretive Dynamic Transactional Analysis Psychotherapy
 
ESET 3 internship protocol
ESET 3 internship protocolESET 3 internship protocol
ESET 3 internship protocol
 
Mastering Redecision Therapy
Mastering Redecision TherapyMastering Redecision Therapy
Mastering Redecision Therapy
 
Life Script
Life ScriptLife Script
Life Script
 
The Vital Skill of Clinical Assessment
The Vital Skill of Clinical AssessmentThe Vital Skill of Clinical Assessment
The Vital Skill of Clinical Assessment
 
Psychotherapy from the clients perspective
Psychotherapy from the clients perspectivePsychotherapy from the clients perspective
Psychotherapy from the clients perspective
 
There's No Place Like Home
There's No Place Like HomeThere's No Place Like Home
There's No Place Like Home
 
Advanced Counselling Skills
Advanced Counselling SkillsAdvanced Counselling Skills
Advanced Counselling Skills
 
CATA conference 2023.pdf
CATA conference 2023.pdfCATA conference 2023.pdf
CATA conference 2023.pdf
 
UKATA Conference 2023
UKATA Conference 2023UKATA Conference 2023
UKATA Conference 2023
 
Applied TA in clinical practice
Applied TA in clinical practiceApplied TA in clinical practice
Applied TA in clinical practice
 
Intensive course - Working with therapeutic cards
Intensive course - Working with therapeutic cardsIntensive course - Working with therapeutic cards
Intensive course - Working with therapeutic cards
 
Personality Focused Treatment
Personality Focused TreatmentPersonality Focused Treatment
Personality Focused Treatment
 
Advanced training in Transanctional analysis
Advanced training in Transanctional analysisAdvanced training in Transanctional analysis
Advanced training in Transanctional analysis
 
Magdalena internship protocol
Magdalena internship protocolMagdalena internship protocol
Magdalena internship protocol
 
PPP internship protocol
PPP internship protocolPPP internship protocol
PPP internship protocol
 

Dernier

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 

Dernier (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

When assertthat(you).understandUnitTesting() fails

  • 1. Advanced testing techniques When assertThat(you).understandUnitTesting() fails 23 October 2014 Martin Škurla, Equities IT
  • 2. Speaker’s Bio • Ing. Martin Škurla • Certifications • Sun Certified Programmer for the Java 2 Platform, Standard Edition 6.0 • Oracle Certified Professional, Java EE 5 Web Component Developer • Open Source Committer • Gephi (GSoC 2010), NetBeans (NetCAT), Abego Tree Layout, AST Visualizer, Tyrus • Conference/JUG Speaker • Fosdem, CZJUG, GeeCON • Technical Reviewer • CPress, Grada, Manning • Previous work experience • Sors Technology, ESET, Celum, Atlassian • Currently • PSEC at Barclays 2 | Advanced testing techniques | 23 October 2014 COPYRIGHT © Copyright Barclays Bank PLC, 2014 (all rights reserved).
  • 3. “More than the act of testing, the act of designing tests is one of the best bug preventers known. The thinking that must be done to create a useful test can discover and eliminate bugs before they are coded – indeed, test-design thinking can discover and eliminate bugs at every stage in the creation of software, from conception to specification, to design, coding and the rest.” [1] 3 | Advanced testing techniques | 23 October 2014 Boris Beizer [1] Software Testing Techniques, Creating a Software Engineering Culture by Karl Eugene Wiegers, ISBN: 0932633331 , Page: 211
  • 4. Agenda • Test face-lifting • naming conventions • logical grouping • test code smells and “refactoring patterns” • bad practices and pitfalls • Custom assertions • Declarative and Data driven testing • Advanced techniques • TestNG framework integration • concurrent test execution • Results (code reduction, number of tests, execution time) 4 | Advanced testing techniques | 23 October 2014
  • 5. Naming conventions • The most important asset of a unit test is readability. • We try to achieve “readable tests” • readable vs. understandable tests • Test method naming conventions: • testNameOfTheMethod() antipattern • method name should contain 3 parts: behavior being tested, inputs and outputs • e.g. attrUsedInRules_ShouldNotBeAbleToRemove(), removingAttrUsedInRules_ShouldThrowIllegalArgumentException(), ruleEqualsAndHashCodeMethods_ShouldBeCorrectlyImplemented(), getAttrVal_ShouldThrowExceptionWhenAmbiguityHappens() • Test lifecycle method naming conventions: • setUp() & tearDown() antipatterns • e.g. @BeforeMethod public void rulesInit() {…} 5 | Advanced testing techniques | 23 October 2014
  • 6. Logical grouping • Don’t put all test code related to single class/method always into the same test class. • NameOfClassTest antipattern • it doesn’t scale for anything but trivial examples • Instead, you should group tests logically. • AE has attributes, attribute groups, cross rule validation, distinct rules, matching expressions, meta rules, querying API, rule ambiguities handling, rule precedence, target expressions, transactional behavior • e.g. AttrManipulationTest, AttributeEngineTest, AttrGroupTest, CrossRuleValidationTest, DistinctRuleTest, GettingAttrsRulesAndValsAPITest, MatchingAttrExpressionsTest, MetaRuleManipulationTest, MetaRulesTest, RuleAmbiguitiesTest, RuleManipulationTest, RuleMatchValsTest, RulePrecedenceTest, TargetAttrExpressionsTest, TransactionalBehaviorTest 6 | Advanced testing techniques | 23 October 2014
  • 7. Test code smells and “refactoring patterns” • Conditions • introducing multiple test execution paths is bad • => multiple tests, JUnit assumptions, TestNG SkipException • Loops • introducing multiple test cases into a single test is bad • => parameterized testing, more powerful (custom) assertions • Assertions on different objects • test should only assert on a single object: SUT • => refactoring to multiple tests • Multiple assignments into the same variable • reinitializing the SUT is bad • => refactoring to multiple tests 7 | Advanced testing techniques | 23 October 2014
  • 8. “Yesterday’s best practices is tomorrow’s anti-pattern.” [2] 8 | Advanced testing techniques | 23 October 2014 Neal Ford [2] GeeCON Prague 2014 Conference, This is water, Opening Keynote
  • 9. Bad practices • Using assertTrue(), assertFalse(), assertEquals() • => use custom assertions • Sophisticated string assertion description • assertEquals(String message, Object expected, Object actual); • => use custom assertions • Logging and printing into console • => remove it • Boolean asserted aggregation • => rewrite to multiple tests • Sophisticated tests • GC tests, memory leak tests, latency tests • => remove them 9 | Advanced testing techniques | 23 October 2014
  • 10. Common pitfalls • Removing repetition • some level of repetition is actually good • => don’t do that • Introducing constants • test constants should only be introduced if the particular value is not important for test • => don’t introduce constants as in normal code • SUT initialization in @BeforeMethod • not conforming to arrange-act-assert • not directly obvious how SUT is initialized • introduces mutability (stay tuned) • => don’t initialize SUT in @BeforeMethod if not necessary • Reusing SUT • you might be relying on already modified state • => never reuse already used SUT 10 | Advanced testing techniques | 23 October 2014
  • 11. Agenda • Test face-lifting • naming conventions • logical grouping • test code smells and “refactoring patterns” • bad practices and pitfalls • Custom assertions • Declarative and Data driven testing • Advanced techniques • TestNG framework integration • concurrent test execution • Results (code reduction, number of tests, execution time) 11 | Advanced testing techniques | 23 October 2014
  • 12. Custom assertions • Because of readability • assertThatAttr(“T1”).hasDescription(“…”); • Very useful when API is leaking implementation details • e.g. returning complicated data structures • assertThatUnsuppressedRules(rules).containRulesOnLines(1, 2); assertThatSuppressedRules(rules).isNull(); • Very powerful when custom assertions reuse other custom assertions • assertThatException(e).forRuleOnLine(1).hasDependentCount(1) .forRuleOnLine(2).hasDependentCount(2); • Think twice before adding custom assertions. 12 | Advanced testing techniques | 23 October 2014
  • 13. Agenda • Test face-lifting • naming conventions • logical grouping • test code smells and “refactoring patterns” • bad practices and pitfalls • Custom assertions • Declarative and Data driven testing • Advanced techniques • TestNG framework integration • concurrent test execution • Results (code reduction, number of tests, execution time) 13 | Advanced testing techniques | 23 October 2014
  • 14. Declarative and Data driven testing • Data driven testing • testing the same code, but with different inputs and outputs • Declarative testing • tests are saying what to do and not how @DataProvider private String[][] attrGroupDataProvider() { return new String[][] {{“XETRA”, “b111”, “rule2”}};} @MatchingAttrDelimiter(“!”) @AeColumns(“M1 ! M2 || +M1 || T1 ”) @AeRules( {“LSE ! || EUROPE || ”, “+EUROPE” ! /a111 || || rule1”) @Test(dataProvider= “attrGroupDataProvider” ) public void attrGroup_...(String m1, String m2, String expT1) {} 14 | Advanced testing techniques | 23 October 2014
  • 15. Agenda • Test face-lifting • naming conventions • logical grouping • test code smells and “refactoring patterns” • bad practices and pitfalls • Custom assertions • Declarative and Data driven testing • Advanced techniques • TestNG framework integration • concurrent test execution • Results (code reduction, number of tests, execution time) 15 | Advanced testing techniques | 23 October 2014
  • 16. TestNG framework integration • TestNG listeners • for handling declarative testing • @AEColumns, @AEFileResources, @AERules, @MatchingAttrDelimiter, @MetaAEColumns, @MetaAERules, @TrimOnlyLeadingAndTrailingSpaces • listeners should play nicely with data providers • listeners should support concurrency • But how does it feel like to integrate into TestNG? • happiness followed by hacking3 private static final Set<String> UGLY_HACK = new HashSet<String>(); • you have to expect issues • internal bugs (Maven surefire plug-in) • workarounds (ROCK-581) 3 “to devise or modify (a computer program), usually skillfully” according to http://dictionary.reference.com/browse/hacking?s=t 16 | Advanced testing techniques | 23 October 2014
  • 17. Concurrent test execution • The point of adding concurrency into tests was surprisingly not performance. • the reason was the independence (isolation) • Different granularities • test suites, test classes, test methods • Achievable by removing all unnecessary and guarding the necessary shared state. • application of thread-safety and functional principles • Test framework integration • solid understanding of the testing framework thread model is essential • But what to do when thread-safety cannot be achieved? • @Test(singleThreaded = true) • JVM forking (last resort solution) 17 | Advanced testing techniques | 23 October 2014
  • 18. Agenda • Test face-lifting • naming conventions • logical grouping • test code smells and “refactoring patterns” • bad practices and pitfalls • Custom assertions • Declarative and Data driven testing • Advanced techniques • TestNG framework integration • concurrent test execution • Results (code reduction, number of tests, execution time) 18 | Advanced testing techniques | 23 October 2014
  • 19. Results • JIRA issues resolved: • specifically created: ROCK-349, ROCK-395, ROCK-396, ROCK-397, ROCK-481, ROCK-613 • resolved as a side-effect of refactoring: ROCK-295 • TestNG workarounds: ROCK-581 • won’t fix: ROCK-511 • introduced bug: ROCK-585 • pending: ROCK-495 • Testable documentation • This is in line with Barclay’s Values including Stewardship 19 | Advanced testing techniques | 23 October 2014
  • 20. Results 40 35 30 25 20 15 10 600 550 500 450 400 350 300 250 200 150 100 Before ROCK-349 ROCK-397 ROCK-396 ROCK-395 ROCK-481 ROCK-613 Number of tests Execution time (sec) 65000 60000 55000 50000 45000 40000 35000 30000 550 500 450 400 350 300 Before ROCK-349 ROCK-397 ROCK-396 ROCK-395 ROCK-481 ROCK-613 Test code size (kB) Test resources size (kB) • Number of tests: • 373.38% • Execution time: • 42.64% • Number of lines: • 61.57% • Test code size: • 63.99% • Test resources size: • 57.45% 20 | Advanced testing techniques | 23 October 2014
  • 21. More on testing libraries, books • Links4: • http://testng.org/doc/index.html • http://code.google.com/p/hamcrest/ • http://joel-costigliola.github.io/assertj/ • http://code.google.com/p/catch-exception/ • http://www.manning.com/koskela2/ • http://www.manning.com/osherove2/ 4 These links were accessed on 23/09/2014. The websites are those of third parties and Barclays is not responsible for any information stated to be obtained or derived from these third party sources. 21 | Advanced testing techniques | 23 October 2014
  • 22. Q & A 22 | Advanced testing techniques | 23 October 2014
  • 23. 23 | Advanced testing techniques | 23 October 2014
  • 24. Thank you for your attention
  • 25. Disclaimer CONFLICTS OF INTEREST BARCLAYS IS A FULL SERVICE INVESTMENT BANK. In the normal course of offering investment banking products and services to clients. Barclays may act in several capacities (including issuer, market maker, underwriter, distributor, index sponsor, swap counterparty and calculation agent) simultaneously with respect to a product, giving rise to potential conflicts of interest which may impact the performance of a product. NOT RESEARCH This document is from a Barclays Trading and/or Distribution desk and is not a product of the Barclays Research department. Any views expressed may differ from those of Barclays Research. BARCLAYS POSITIONS Barclays, its affiliates and associated personnel may at any time acquire, hold or dispose of long or short positions (including hedging and trading positions) which may impact the performance of a product. FOR INFORMATION ONLY THIS DOCUMENT IS PROVIDED FOR INFORMATION PURPOSES ONLY AND IT IS SUBJECT TO CHANGE. IT IS INDICATIVE ONLY AND IS NOT BINDING. NO OFFER Barclays is not offering to sell or seeking offers to buy any product or enter into any transaction. Any transaction requires Barclays’ subsequent formal agreement which will be subject to internal approvals and binding transaction documents. NO LIABILITY Barclays is not responsible for the use made of this document other than the purpose for which it is intended, except to the extent this would be prohibited by law or regulation. NO ADVICE OBTAIN INDEPENDENT PROFESSIONAL ADVICE BEFORE INVESTING OR TRANSACTING. Barclays is not an advisor and will not provide any advice relating to a product. Before making an investment decision, investors should ensure they have sufficient information to ascertain the legal, financial, tax and regulatory consequences of an investment to enable them to make an informed investment decision. THIRD PARTY INFORMATION Barclays is not responsible for information stated to be obtained or derived from third party sources or statistical services. PAST & SIMULATED PAST PERFORMANCE Any past or simulated past performance (including back-testing) contained herein is no indication as to future performance. OPINIONS SUBJECT TO CHANGE All opinions and estimates are given as of the date hereof and are subject to change. Barclays is not obliged to inform investors of any change to such opinions or estimates. NOT FOR RETAIL This document is being directed at persons who are professionals and is not intended for retail customer use. IMPORTANT DISCLOSURES For important regional disclosures you must read, click on the link relevant to your region. Please contact your Barclays representative if you are unable to access. EMEA EMEA Disclosures APAC APAC Disclosures U.S. US Disclosures IRS CIRCULAR 230 DISCLOSURE: Barclays does not provide tax advice. Please note that (i) any discussion of US tax matters contained in this communication (including any attachments) cannot be used by you for the purpose of avoiding tax penalties; (ii) this communication was written to support the promotion or marketing of the matters addressed herein; and (iii) you should seek advice based on your particular circumstances from an independent tax advisor. CONFIDENTIAL This document is confidential and no part of it may be reproduced, distributed or transmitted without the prior written permission of Barclays. ABOUT BARCLAYS Barclays Bank PLC offers premier investment banking products and services to its clients through Barclays Bank PLC. Barclays Bank PLC is authorised by the Prudential Regulation Authority and regulated by the Financial Conduct Authority and the Prudential Regulation Authority and is a member of the London Stock Exchange. Barclays Bank PLC is registered in England No. 1026167 with its registered office at 1 Churchill Place, London E14 5HP. COPYRIGHT © Copyright Barclays Bank PLC, 2014 (all rights reserved). 25 | Advanced testing techniques | 23 October 2014

Notes de l'éditeur

  1. 0-5 min
  2. 5-10 min
  3. 10-15 min
  4. 15-20 min
  5. 20-25 min
  6. 25-30 min
  7. 0-5 min
  8. 30-35 min
  9. 0-5 min
  10. 35-40 min
  11. 0-5 min
  12. 40-45 min
  13. 45-50 min
  14. 0-5 min