Advanced Software Testing



Similar documents
Test-Driven Development

Upping the game. Improving your software development process

RUnit - A Unit Test Framework for R

Software Construction

Java course - IAG0040. Unit testing & Agile Software Development

Code Quality Assurance. Peter Kofler, Code Cop FH Technikum Wien, February 2010

E-vote 2011 Version: 1.0 Testing and Approval Date: 26/10/2009. E-vote SSA-U Appendix 5 Testing and Approval Project: E-vote 2011

Good Software. Lecture 6 GSL Peru 2014

Practicing Continuous Delivery using Hudson. Winston Prakash Oracle Corporation

Fail early, fail often, succeed sooner!

SOFTWARE DEVELOPMENT BASICS SED

Jenkins User Conference Herzelia, July #jenkinsconf. Testing a Large Support Matrix Using Jenkins. Amir Kibbar HP

Content. Development Tools 2(63)

Continuous Integration

Continuous Integration with Jenkins. Coaching of Programming Teams (EDA270) J. Hembrink and P-G. Stenberg [dt08jh8

Massively! Continuous Integration! A case study for Jenkins at cloud-scale

Chapter 11, Testing, Part 2: Integration and System Testing

Basic Testing Concepts and Terminology

Software Development Tools

Software Engineering I: Software Technology WS 2008/09. Integration Testing and System Testing

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

SAP Technical Brief SAP NetWeaver. Increase IT Productivity with ABAP Development Tools for SAP NetWeaver

Unit Testing webmethods Integrations using JUnit Practicing TDD for EAI projects

How To Write Unit Tests In A Continuous Integration

Build Automation for Mobile. or How to Deliver Quality Apps Continuously. Angelo Rüggeberg

Agile.NET Development Test-driven Development using NUnit

Java Software Quality Tools and techniques

Co-Presented by Mr. Bill Rinko-Gay and Dr. Constantin Stanca 9/28/2011

Jenkins on Windows with StreamBase

Winning the Battle against Automated Testing. Elena Laskavaia March 2016

Effective unit testing with JUnit

Performance Testing and Optimization in Web-Service Based Applications

National University of Ireland, Maynooth MAYNOOTH, CO. KILDARE, IRELAND. Testing Guidelines for Student Projects

Continuous Keylane

Real-Time Analytics on Large Datasets: Predictive Models for Online Targeted Advertising

Analysis Tools and Libraries for BigData

Coding for the enterprise server

Software Engineering Principles The TriBITS Lifecycle Model. Mike Heroux Ross Bartlett (ORNL) Jim Willenbring (SNL)

Automation and Virtualization, the pillars of Continuous Testing

In this Lecture you will Learn: Implementation. Software Implementation Tools. Software Implementation Tools

GUI Test Automation How-To Tips

Monitoring, Tracing, Debugging (Under Construction)

Coding in Industry. David Berry Director of Engineering Qualcomm Cambridge Ltd

Two Best Practices for Scientific Computing

Using Power to Improve C Programming Education

Software Engineering. Top-Down Design. Bottom-Up Design. Software Process. Top-Down vs. Bottom-Up 13/02/2012

Best Overall Use of Technology. Jaspersoft

Patterns to Introduce Continuous Integration to Organizations

Evaluation of AgitarOne

Oracle Solaris Studio Code Analyzer

Continuous Integration: Improving Software Quality and Reducing Risk. Preetam Palwe Aftek Limited

Software testing. Objectives

Secrets to Automation Success. A White Paper by Paul Merrill, Consultant and Trainer at Beaufort Fairmont, LLC

Multi-GPU Load Balancing for Simulation and Rendering

An Introduction to text-based test automation and the TextTest tool

Eliminate Memory Errors and Improve Program Stability

We ( have extensive experience in enterprise and system architectures, system engineering, project management, and

A Pythonic Approach to Continuous Delivery

Testing: Python, Java, Groovy, etc.

An Example Checklist for ScrumMasters

Testing Automation for Distributed Applications By Isabel Drost-Fromm, Software Engineer, Elastic

XP & Scrum. extreme Programming. XP Roles, cont!d. XP Roles. Functional Tests. project stays on course. about the stories

JOURNAL OF OBJECT TECHNOLOGY

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

Announcement. SOFT1902 Software Development Tools. Today s Lecture. Version Control. Multiple iterations. What is Version Control

How In-Memory Data Grids Can Analyze Fast-Changing Data in Real Time

Software Configuration Management and Continuous Integration

Course MS10975A Introduction to Programming. Length: 5 Days

Advanced Test-Driven Development

Continuous Integration

Achieving business benefits through automated software testing. By Dr. Mike Bartley, Founder and CEO, TVS

Review of ACN Working Environment

Source Code Review Using Static Analysis Tools


Unit Testing & JUnit

Continuous Delivery. Alejandro Ruiz

How to Optimize Automated Testing with Everyone's Favorite Butler

Building, testing and deploying mobile apps with Jenkins & friends

Faculty of Science and Technology MASTER S THESIS

Test Driven Development Part III: Continuous Integration Venkat Subramaniam

Quality Assurance Plan

pbuilder Debian Conference 2004

Modern practices TIE-21100/

Fully Automated Static Analysis of Fedora Packages

CSCI E 98: Managed Environments for the Execution of Programs

RevoScaleR Speed and Scalability

Transcription:

Johan Seland Advanced Software Testing Geilo Winter School 2013 1

Solution Example for the Bowling Game Kata Solution is in the final branch on Github git clone git://github.com/johanseland/bowlinggamekatapy.git git checkout origin/final 2

Overview of Lecture Testing Frameworks Writing good tests The mechanism of change Refactoring Black-Box testing tools Continuous Integration 3

The Test Pyramid Regression Tests System Tests Integration Tests Unit Tests 4

The Test Pyramid Regression Tests System Tests Unit Tests: Tests individual units of code Function/Class level Integration Tests: Tests how components communicate Example: Is grid correctly initialized from init file? System Tests: Are results valid? Performance/Scaling/Resources/Stability Regression Tests: Test for old bugs Integration Tests Unit Tests 5

xunit Test Frameworks Testing software is made easier by test frameworks At least for unit, integration and regression tests Typical facilities Automatic test detection Minimize boilerplate-code Assertion functions Test execution Tests run in isolation Command-line parsing Standard output formats Common terminology for talking about tests 6

xunit Testing terminology Assertions The actual tests Test case Function invoking assertions Suites A collection of cases Fixtures (Data) structures set up before tests Mocks objects Objects that mimic behavior of real objects 7

Every language has a xunit-based Test Framework C++ GoogleTest, Qtest, Boost.Test Fortran: pfunit, funit.net (C#, F#, etc.) Visual Studio Testing Framework Java Junit Python UnitTest R Runit Matlab MUnit Open Source 8

Test code organization Split test and source files! Consider building application as Library + "App"-executable Test-executables Separate project for different test layers Unit vs Integration vs System vs Regression make should build everything make check should run as reasonable amount of tests Unambiguous answer if tests pass or fail 9

Testing best practices Test code is not a second-class citizen Requires thought, design and care It must be kept as clean as production code Agree on naming convention TestFoo() or FooTest()? Test one concept per test Often multiple tests per class/function Kent Beck school: One assert per test 10

What to unit test? Be intelligent when writing unit tests! Do not inflate their number Each test should have a meaning Collapse/Cleanup tests when cleaning up the production code Typically test: Zero-case Trivial Case Corner Cases (division by zero?) Error handling 11

Clean tests F.I.R.S.T. Fast Tests should be fast. You won t run slow tests frequently Independent Tests should not depend on each other Repeatable They should be repeatable in any environment Otherwise you have an excuse why they fail Self-Validating Tests should have a boolean output No manual evaluation should be needed Timely Should be written just before the production code that make pass 12

Testing private methods Short answer: You should only test the public interface of a class Reality: The crucial computation happens in private methods Possible fixes: Split into impl-namespace Mark as protected instead and let test-class be subclass Let test be a friend class (C++) Mark as package-private (Java) 13

Testing Floating Point Computations HERE BE DRAGONS! Floating point in general is not associative a op b!= b op a Beware of parallel computations Floating point is sensitive to compiler settings! Fused operations Compiler optimizations Flush to memory Know your precision 14

Testing Floating Point cont'd For numerical algorithms, an estimate of the tolerance is needed You can not simply test for equality Absolute vs Relative error Too low tolerance: Test might fail when implementation is correct Too high tolerance: Test will not detect real errors Do you have (or can derive?) an error estimate/bound Might be publishable itself! Might just be asymptotic with unknown coefficient 15

Unit Tests for Iterative Methods Unit tests is not the place to test for stability of iterative methods A black-box or system test Will often require manual inspection of results Goal of automated tests should be to decide if the implementation is correct Unit tests for iterative methods should test the implemenation Constant input fields Convergence criteria Detecting invalid input Can you split it out so each substep has an analytical solution? 16

Strategies for Testing Floating Point Use analytic cases when available! Write tests to compare results between previous run of simulator Typically require manual inspection Often require dedicated post-processing tools Bitwise reproducibility is not attainable 17

Mocks and fakes Often you can not rely on real objects for tests Databases Sockets Huge datasets Displays Amazon Instances FAKE objects have working implementation with shortcuts In-memory filesystem, constant grids MOCK objects are pre-programmed with expectations Mock-libraries make it easier 18

Using Fakes: Non-testable code Use of InputFileReader is hardcoded in class (tight coupling) Problems: I/O might take a long time Input files must be distributed with tests 19

Using Fakes: Introduce Parameter Object We instead use an abstract class defining our behaviour Parameter object is passed to simulator 20

Using Fakes: Introduce fake object In the test code, we add simplified version And pass this to simulator 21

Fake objects conclusion Testable code will often have: More classes Should not be a problem in modern IDEs Use ECB in Emacs Smaller classes That follow the Single Responsibility Principle (SRP) Looser coupling One of the benefits of object-oriented languages 22

Changing software Why do you want change? 1. To add a feature 2. To fix a bug 3. To improve the design (refactoring) 4. To optimize 23

The mechanisms of change cont'd Add a Feature Fix a bug Refactoring Optimizing Structure Changes Changes Changes Changes? New Functionality Changes - - - Functionality - Changes - - Resource Usage - - - Change 24

What about legacy code? The main thing that distinguishes legacy code from non-legacy code is tests, or rather a lack of tests." Michael Feathers Alternative definition: Code you are afraid to change, cause you can not see the consequences BRING IT UNDER TEST! 25

Refactoring Code refactoring is the process of changing a computer program's source code without modifying its external functional behavior in order to improve some of the nonfunctional attributes of the software Make it work Make it right Maintainability Extensibility 26

Some refactoring techniques Rename field Change a name into a new one that better reveals its purpose Extract method Turn part of a larger method into a new method Move field Move to a more appropriate class or source file Extract class Move part of the code from an existing class into a new class Generalize Type Create more general types to allow for more code sharing Many more at refactoring.com 27

Refactoring in practice IDEs have some support for automatic refactoring Guarantees that behavior does not break Java IDE have C++ is probably the most difficult language Templates are specially difficult But we are getting there as well (QTCreator in particular) Lean on the compiler 1. Alter declarations to cause compile errors 2. Navigate to errors and make changes 3. Rerun tests! Pair programming! 28

Other testing tools A plethora of tools to analyse your program and tell you something about is status At the source-code level or program level Commercial or open-source White-box testing is biased You generally write them yourself Testing tools does not lie 29

Static Code Analysers Programs that look at your source code Identifies common errors Bounds checking for arrays Memory leaks Resource leaks Stylistic errors Code duplication Compute code metrics Subject to false positives and negatives Common tools: Cppcheck, Cpplint 30

Profilers Tools that monitor the execution of a program Allows you to understand their behaviour when running on real code Used to detect: Performance metrics Memory leaks Parallelization errors Program must be instrumented Compiler switch Run in a virtual environment Often program execution is slowed down dramatically Yet another benefit of many separate test programss Example Tools: Valgrind, gcov, Intel Parallel Studio 31

Code coverage Measure which code is executed at all Used to detect if you have code that is not covered your tests Are you testing each direction of an if-statement? Is it code you are not executing Example programs: gcov (GCC stack), Cobertura (Java), coverage (Python) 32

CONTINOUS INTEGRATION 33

Motivation If daily builds are good Continuous builds are better If daily testing is good Continuous testing is better Detect issues as early as possible Jenkins is a web-service that happily builds code and executes test all-day Jenkins will build on all your platforms Execute long-running tests Syndicate results across builds 34

35

Benefits Instant feedback Everyone can see status Latest executable available Build on all platforms all the time Downside: Should really be run on dedicated server 36

Jenkins best practices Email only when build breaks/tests start to fail Per project participant list If people start filtering emails you have lost Everyone can look at build configurations Avoids mysterious cron jobs on private workstations Jenkins is not a high-security system Do not build on your own workstation Highlights new dependencies Use clean builds 37

Jenkins slaves You need something not on Jenkins server Matlab Windows GPUs Fluent Hudson can start jobs on slaves Extremely easy to set up 38

Jenkins tips Performance monitoring Runtime for test is in XML-report Small Python script to extract it Correctness monitoring Compare output to prev. output Get cron jobs in there as well Back up Hudson! 39

More possibilities Store profiling information Validate single-thread vs parallel implementations Validate against gold standard Analyze compiler warnings Static code analyzer Check for memory leaks (Valgrind) Let managers/supervisor know about available metrics? 40

Jenkins at SINTEF Applied Mathematics Server was set up in summer 2010 Specialized servers added later GPU build server Windows build server Informal tutorial session Quickly adopted for many projects People continue to use it! 41

Thing not covered Social Processes Code-Reviews Pair-Programming Bug/Issue tracking Acceptance Testing Fitnesse Framework Various code metrics 42

Concluding remarks You need a testing strategy Your testing strategy should consist of a battery of White-box testing at the source level Black-box testing at the program level Automate as much as possible Minimize the amount of human parsing necessary Execute tests as often as possible Continuous Integration is an enabling technology for this 43

Reading list 44