230 likes | 351 Views
SW Testing - part of a better Process. CERN-BE-BI-SW Training Day M.Andersen. Testing late vs. early. Why is software late & buggy?. 1. Rushed timetables ->Hope is lost 2. Lousy design -> Hope is there 3. Inadequate testing -> Hope is there Jack Ganslle – Embedded SW Guru
E N D
SW Testing -part of a better Process CERN-BE-BI-SW Training Day M.Andersen
Why is software late & buggy? 1. Rushed timetables ->Hope is lost 2. Lousy design -> Hope is there 3. Inadequate testing -> Hope is there Jack Ganslle – Embedded SW Guru Unlike HW which still can break under load, a tested SW stays always perfect!
How do we test? cout<<“value=”<val<<endl; System.out.println(“value=”+val); Main() { MyNewClass a = new MyNewClass(); a.doMethod(); a.doMethod(); cout<< a.data()<<endl; }
When to test? • When left to the end of the project, which is running late... testing is the last thing on your mind. • Final functional testing only covers 20% of the code! • Only 20% is new code writing so you won’t escape, 80% is bugfixing and testing anyway! • XP: Write software tests software, before or at least at the same time with coding features Input Output
Test Driven Development 1 • Writing tests clarifies the purpose of the code. • Goes in hand with specs • Reduces time in rework • Less time spent debugging • Code simplification • You only do what is needed to test • You think in smallmodules to be tested
Test Driven Development 2 • Makes code less coupled- thus reusable Improves quality and reduces bugs by: • Making you think in terms of purpose and specs. • Simple≠ Complexity↔Bugs • Maintainable http://agilepainrelief.com/notesfromatooluser/2008/10/advantages-of-tdd.html
Does it work? • "measuring a over 20 projects: if you have a large number of unit tests your code will be an order of magnitude (x10) less complex.“ • Controlled study results: • “..quality increased linearly with the number of programmer tests...” • “..test-first students on average wrote moretests and, in turn, students who wrote more tests tended to be more productive...” http://agilepainrelief.com/notesfromatooluser/2008/11/misconceptions-with-test-driven-development.html http://collaboration.csc.ncsu.edu/laurie/Papers/TDDpaperv8.pdf
Types of SW test Unit Test Functional Test Integration Test Load Test Regression Test Acceptance Test Good to be aware which one we are doing
Acceptance (Functional) Testing Acceptance Test document Test Feature A: test case a test case b Test Feature B test case d test case e test case f Test Feature C test case h Requirements document Feature A description Feature B description Feature C description In some companies done by QA section and often outsourced Example Functional specifications example
Unit Testing • Individualcomponents, modules, classes not the final application. • Independent of context • Makes you think and design modular code • Requires extra code • Easy in Java & Eclipse using JUnit
JUnit Step 1 Step 2
JUnit Step 3 assertTrue( d4.hashCode()== d5.hashCode() ); Step 4
Testing GUI in Java Challenge: How to automatetest for a GUI? • You need human to press buttons.. • You need human to read out fields, graphs..
UISpec4J framework • .jar library to put in a class pass. • Uses JUnit • Offers a large set of wrappers for Java Swing graphical components • Allows users to write Unit and Full system tests for Panels or whole GUI Apps
UISpec4J mechanism Button getButton(“Set”) Panel JButton getText() TextBox JPanel JLabel getTextBox() Window MenuBar getPanel() MenuItem JFrame JMenuBar JMenu click() getSubMenu(“Open”) getMenuBar()
Integration Testing with Bamboo • Build server runs on cs-ccr-builds (BE-CO) • Java projects are rebuild with their dependencies • Executes Java JUnit tests at 2:00 at night • Provides a detailed status report from the test runs. • Sends an email with report on success or fail. • http://builds.cern.ch/browse/LHCFB-OFSUTESTS
C++ testing • BE-CO Fesa team started using Google test framework • Profound experience. Direct quote: “ ..The problem with testing is that you discover how bad your code is!...” • You see bugs in code you thought was OK • You see bad design & architecture (tight coupled vs. Loose coupled code, complex dependencies...)
C++ Testable code 1000+ lines of code inside RT action Small loosely coupled objects invoked from RT action Execute() Execute() Obj A Obj B Obj C
References • http://collaboration.csc.ncsu.edu/laurie/Papers/TDDpaperv8.pdf • http://www.uispec4j.org/getting-started • http://www.vogella.de/articles/JUnit/article.html • http://www.softwaretestinghelp.com/types-of-software-testing/ • http://searchsoftwarequality.techtarget.com/resources/Software-Testing-Best-Practices • http://www.robthefiddler.com/java/using-uispec4j/ • http://java.sun.com/developer/Books/javaprogramming/ant/ant_chap04.pdf