• No results found

Fail early, fail often, succeed sooner!

N/A
N/A
Protected

Academic year: 2021

Share "Fail early, fail often, succeed sooner!"

Copied!
22
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

Contents

• Beyond testing

• Testing levels

• Testing techniques

• TDD = fail early

• Automate testing = fail often

• Tools for testing

(3)
(4)

Testing in different levels

§ Unit testing

§ Does a single object work? § Integration testing

§ Do multiple objects work together? § Functional testing

§ Does my application work?

§ Acceptance testing

§ Does the customer like my application? § Regression testing

§ Does a bug fix result in another fault in the application?

(5)

Techniques used in testing:

§ white-box testing

§ You know the code and you do your best to break the code

§ grey-box testing

§ You peek a little inside, e.g. know the architecture § black box testing

§ Focuses on input and output

(6)

Fail early i.e. Test-Driven Development practice

W rite a Test Case --> W atch it Fail --> Fix it --> W atch it pass --> Refactor the code

Red

Green Refactor

Write a test to fail

Make the code work Tidy up, eliminate

(7)

§ All failing § Order of

(8)

Pros and cons of TDD

§ It’s hard to learn and master

§ You have to accept that some of the tests become obsolete (you have to

delete them)

§ You trust too much on your tests (remember: they are code just like any other code)

§ You might try to fix the tests to show green by making ad hoc decisions forgetting to solve the real problem

§ W riting tests first require you to really consider what you want from the code § Creates a detailed specification (you

understand the problem better)

§ Less time spent in the debugger and when it is required you usually get closer to problem quickly

§ Tells you whether your last change (or refactoring) has broken previously

working code

§ Allows the design to evolve and adapt to your changing understanding of the problem.

§ Unit tests are simple and act as documentation for the code

(9)

Fail often i.e. test automation

§ Automate the tests, and the tests can be run whenever

§ Automate the tests, and free developers time to more challenging problems

§ Automate the tests, and run them on a separate server not in the developer’s setup

§ Automate the tests, and you get a regression test suite

(10)
(11)

Continuous integration

§ Continuous integration wraps version control, compilation and testing into a single repeatable process

§ CI is a software development practice where members of a team integrate their work

frequently, usually each person integrates at least daily - leading to multiple integrations per day.

§ Each integration is verified by an automated

build (including test) to detect integration errors as quickly as possible.

(12)

Continuous integration server like Jenkins

(13)

Continuous integration server like Jenkins

§ Shows how tests are succeeded in

separate builds

§ Shows for example FindBugs static

analyzer trend

Dm: Found reliance on default encoding in sofa.model.MapBuilder.loadMap():

Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable.

(14)

Tools for unit testing

§ There are hundreds of tools for different levels of testing

§ One popular family is <x>Unit family for different programming languages: Junit, Cunit, CppUnit, PHPUnit, PyUnit, JsUnit,….

§ This family can be used for unit testing but also for integration testing/ functional testing

(15)

Unit Test Types

§ Basic -- cases with small to medium sized inputs that are so simple they should obviously work. § Calling every method in several ways

§ Call assertEquals(x, y) also in case it returns false

§ Edge -- these are also cases that are simple but represent edge conditions -- the empty string, the empty list, etc.

§ Advanced -- harder, more complex cases. Testing e.g. using the knowledge about the code, synchronization, complex algorithms,

(16)

<x>Unit

§ All of the <x>Unit family of testing libraries rely on test cases where you basically make a

proposition or claim of the behaviour of the program.

§ You claim that if your programs gets a certain

input, it will give back an output you want. These are called assertions.

§ Junit is introduced in the Java testing session

(17)

Assertions (many more available)

§ fail(String message)

§ Gives a message that test didn’t go through § assertTrue(String message, boolean condition)

§ Checks if the condition is true

§ assertFalse(String message, boolean condition) § Checks if the condition is

§ assertEquals(Object expected, Object actual) § Checks if the parameters expected and actual

(18)

C and C++

§ CodeLite and Code::Blocks IDE’s are introduced in the C testing session

§ CodeLite has integrated UnitTest++ and this will also be introduced in C testing session

§ CodeLite is not <x>Unit family but has something similar:

CHECK_EQUAL(10, i);

(19)

Acceptance testing

§ Acceptance tests are black box test cases that are jointly written by a developer and a

customer.

§ An acceptance test is a concrete situation, or scenario, that the system might encounter when using the functionality of a user story.

(20)

Summary

§ Change your perspective from developer to tester!

§ Write tests as early as possible!

(21)

Further reading

§ Head First Software Development, By: Dan

Pilone & Russ Miles Publisher: O'Reilly Media, Inc.

§ http://www.agiledata.org/essays/tdd.html by

Scott W. Ambler

§ The Art of Agile Development: Test-Driven Development by James Shore

http://www.jamesshore.com/Agile-Book/test_driven_development.html § And many many more….

(22)

References

Related documents

However, including soy- beans twice within a 4-yr rotation decreased cotton seed yield by 16% compared to continuous cotton across the entire study period ( p &lt; 0.05); whereas,

Since, financial development of India as of late is driven principally by administrations division and inside administrations segment by data innovation (IT) and

• Follow up with your employer each reporting period to ensure your hours are reported on a regular basis?. • Discuss your progress with

Using text mining of first-opinion electronic medical records from seven veterinary practices around the UK, Kaplan-Meier and Cox proportional hazard modelling, we were able to

Biofilm production by selected strains of bacteria (a) and yeasts (b) in the presence of Textus bioactiv, Textus multi dressings, and culture broth without dressing.. The figures

There are infinitely many principles of justice (conclusion). 24 “These, Socrates, said Parmenides, are a few, and only a few of the difficulties in which we are involved if

Machine learning techniques applied to electronic health record data provide a potential solution to the problem of sepsis categorization by enabling phenotype discovery without

It was decided that with the presence of such significant red flag signs that she should undergo advanced imaging, in this case an MRI, that revealed an underlying malignancy, which