Introduction to Automated Unit Testing (xunit) Brian Nielsen Arne Skou

Similar documents
Introduction to C-Unit test Framework (Cutest) Brian Nielsen Arne Skou

Object Oriented Software Design - I

Automated testing in Agile SW development

Practical Objects: Test Driven Software Development using JUnit

JUnit tes)ng. Elisa Turrini

Philosophy of Unit Testing

Test Driven Development TDD

Tuesday, November 15. Testing

TEST DRIVEN DEVELOPMENT

Analysis of the Test Driven Development by Example

Test First Software Development

Automated Acceptance Testing

Chapter 15. Software Testing The assert Statement

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy

Lab Exercise Test First using JUnit

White box testing. White-box testing. Types of WBT 24/03/15. Advanced Programming

Levels of Testing Testing Methods Test Driven Development JUnit. Testing. ENGI 5895: Software Design. Andrew Vardy

COMP s1 Lecture 1

Tools for Unit Test - JUnit

Testing Stragegies. Black Box Testing. Test case

Test-Driven Development (TDD)

Unit Testing with JUnit and CppUnit

Software Testing Workshop 2014 Introduction

JUnit in EDA Introduction. 2 JUnit 4.3

Test-Driven Development JUnit

Software Quality in a Modern Development Team. Presented by Timothy Bauguess and Marty Lewis

Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (testing whatever occurs to you at

Testing. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 13

Growing Embedded Applications Organically with Ceedling and Friends. Greg Williams

Software Engineering. Unit Testing Gobo Eiffel Test and Clover

Test Driven Development (TDD)

Unit Testing and JUnit

Testing. CMSC 433 Programming Language Technologies and Paradigms Spring A Real Testing Example. Example (Black Box)?

Software Design and Analysis for Engineers

16.410: Jump Starting With Java

Introduction to JUnit

Testing with JUnit 1

Junit Overview. By Ana I. Duncan

CSE 15L Winter Midterm :) Review

Introduction to JUnit. Data Structures and Algorithms for Language Processing

Junit. Presentation & Tools (Eclipse, Maven, Mockito, Spring)

Procedures, Parameters, Values and Variables. Steven R. Bagley

Test-Driven Development JUnit

CSE : Python Programming. Packages (Tutorial, Section 6.4) Announcements. Today. Packages: Concretely. Packages: Overview

S A M P L E C H A P T E R

Marthon User Guide. Page 1 Copyright The Marathon developers. All rights reserved.

CS159. Nathan Sprague. September 30, 2015

EECS 4313 Software Engineering Testing

Stephen Edwards. What is unit testing? Manuel Pérez- Quiñones. Virginia Tech. You betcha! For you: Repeatedly check behaviors of many student programs

print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically

Testing. My favourite testing quote: Program testing can be used to show the presence of bugs, but never to show their absence!

Software Design and Analysis CSCI 2040

Introduction INF 5750

MEDIA COMPUTATION DRJAVA. Lecture 11.3 November 7, 2008

UNIT TESTING OF C++ TEMPLATE METAPROGRAMS

STQA Mini Project No. 1

2. Reasons for implementing clos-unit

INTRODUCTION TO JAVA PROGRAMMING JAVA FUNDAMENTALS PART 2

Project Automation. If it hurts, automate it! Jan Pool NioCAD University of Stellenbosch 19 March 2008

Credit where Credit is Due. Lecture 29: Test-Driven Development. Test-Driven Development. Goals for this lecture

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Approach for Unit testing with the help of JUnit...

CHAPTER 1INTRODUCTION... 3 CHAPTER 2INSTALLING ECLIPSE...

Automated GUI testing. How to test an interactive application automatically?

So, You Want to Test Your Compiler?

Test Automation. Fundamentals. Mikó Szilárd

Test automation / JUnit. Building automatically repeatable test suites

Test automation Test automation / JUnit

CSE 8B Intro to CS: Java

EVALUATION COPY. Test-Driven Development Using NUnit and C# Student Guide Revision 4.6. Unauthorized reproduction or distribution is prohibited.

Technical basis. Interfaces. Framework and tool overview

JUnit Howto. Blaine Simpson

Automated Unit Testing A Practitioner's and Teacher's Perspective

Test-Driven Development

Functions. x y z. f (x, y, z) Take in input arguments (zero or more) Perform some computation - May have side-effects (such as drawing)

Stage 11 Array Practice With. Zip Code Encoding

JUnit: The Goals of JUnit

COMP 354 TDD and Refactoring

South Africa

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

The one bit everyone forgets: with JUnit. John Stegeman Xchanging

Software Test. Levels of test. Types of test. Regression test The JUnit tool for unit testing Java programs. System test Integration test Unit test

Tools for Unit Test JUnit

Testworks User Guide. Release 1.0. Dylan Hackers

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

Software Engineering /48

Topic 6: A Quick Intro To C

Unit Testing C Code Cppunit By Example

Outline. Logistics. Logistics. Principles of Software (CSCI 2600) Spring Logistics csci2600/

Completely

Soda Machine Laboratory

Enums. In this article from my free Java 8 course, I will talk about the enum. Enums are constant values that can never be changed.

3 Continuous Integration 3. Automated system finding bugs is better than people

CS 220: Introduction to Parallel Computing. Arrays. Lecture 4

CS11 Advanced Java. Winter Lecture 2

CS 251 Intermediate Programming Coding Standards

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

A few more things about Agile and SE. Could help in interviews, but don t try to bluff your way through

Annotations in Java (JUnit)

CS 351 Design of Large Programs Coding Standards

Transcription:

Introduction to Automated Unit Testing (xunit) Brian Nielsen Arne Skou {bnielsen ask}@cs.aau.dk

Conventional Test Execution Ad hoc manner Manual stimulation & observation E.g. adding a function to a module, which runs tests on the module s functions Uncomenting or deleting test code / drivers / printf /#ifdefs Assert and debug builds Home-brewed test-code and test runners

Automated Testing Code that isn t tested doesn t work Code that isn t regression tested suffers from code rot (breaks eventually) If it is not automated it is not done! Boring Repetitive Necessary Error-prone (for humans) Better done by you than your users

What is a testing framework? A test framework is a software tool for writing and running unit-tests provides reusable test functionality which: Enables automatic execution for regression tests Is standardized Easy to use GUI-test case browser/runner Test report generation

What is a testing framework Programmer Friendly Test cases written in same language as implementation Well integrated in IDE s

What is xunit? A set of Frameworks for programming and automated execution of test-cases X stands for programming language Most Famous is J-UNIT for Java But exists for almost all programming languages C-unit, Cpp-Unit, DUnit, JUnit NUnit, A framework is a collection of classes, procedures, and macros

Basic Use of FrameWork cunit.lib myunit.c C- compiler myunittests.exe myunittests.c Test-report.xml

Concepts Assertions Boolean expression that compares expected and actual results The basic and smallest building-block General: ASSERT (expected, actual) Test Case A class that extends TestCase s A composition of concrete test procedures May contain several assertions and test for several test objectives E.g all test of a particular function Test Suite Collection of related test cases Can be executed automatically in a single command

xunit Object setup teardown TestCase YourClass TestYourClass SomeMethod1 SomeMethod2 Test SomeMethod1 Test SomeMethod2 Test SomeMethod1 and SomeMethod2

Java Example class ClassifyTriangle { public enum TriangleKind { invalidtriangle, equilateraltriangle, isoscelestriangle, scalenetriangle}; public TriangleKind classifytriangle(int a, int b, int c) { return kind; } } public String checktriangle(string[] args) { }

Java Example import junit.framework.test; import junit.framework.testcase; import junit.framework.testsuite; public class ClassifyTriangleTest extends TestCase { protected void setup() { } protected void setup() { } public void testequilateral() { ClassifyTriangle c=new ClassifyTriangle(); assertequals(equilateraltriangle, c.classifytriangle(5,5,5)); //add more tests here } public void testcommandline() { ClassifyTriangle c=new ClassifyTriangle(); assertequals("error Code 40!\n", c.checktriangle({"-1", "Hello World", "-1"}); } public static void main (String[] args) { junit.textui.testrunner.run(classifytriangletest.class); } }

Test Reports C:\NovoUnitTest\TriangleDemo\cppunitDemo>Debug\cppunitDemo.exe.F... c:\novounittest\triangledemo\testtriangle\testtriangle.cpp(30):assertion Test name: TriangleTests::validClassification equality assertion failed - Expected: 1 - Actual : 4 Failures!!! Run: 4 Failure total: 1 Failures: 1 Errors: 0

Test Runner XML file

Advice: xunit style Test cases exhibits isolation Independent of other tests Execution order irrelevant Set up an independent environment setup / teardown methods scenario Each test case performs a distinct logical check one or few asserts per test method BUT consider amount of test code declarations to be written (when a assert fails the test method is stopped and no further asserts are checked). Test expected errors and exceptions

Advice: xunit style Make them fast; If slow, developers won t run them. Smoke test suites Complete test suites All developers must know about them; Everyone who touches the code must run the tests. Add to common code-repository Make test-code as nice and readable as implementation code Documentation, Maintainability

Advice: Daily Builds Regression testing must be automated This requires they report pass/fail results in a standardized way Daily (Nightly) builds and testing Clean & check out latest build tree Run tests Put results on a web page & send mail (if tests fail)

Advice: Version Control Keep test code in a separate directory Keep both tests-sources and implemenation-source in version control Don t checkin unless version passes all tests

Advice: Application Design and program for testability Directly applicable to Pure function libraries API (With some footwork also user interfaces, network-, web-, and database applications)

Advice: xunit principles Write test suite for each unit in the program. All test can be executed (automatically) at any time. For each program modification all tests must be passed before the modification is regarded as complete - regression testing Test First implement later! Originally based on extreme Programming principles: Lightweight software development methodology by programmers for programmers TDD (Test Driven Development) cycle 1. Write test case, and check it fails 2. Write the new code 3. Check that the test passes (and maybe refactor, re-test)

Conclusions Code that isn t tested doesn t work Code that isn t regression tested suffers from code rot (breaks eventually) A unit testing framework enables efficient and effective unit & regression testing Use xunit to store and maintain all the small tests that you write anyway Write tests instead of playing with debugger and printf tests can be automatically repeated

END