Automated Testing with PHPUnit. How do you know your code works?

Slides:



Advertisements
Similar presentations
Acceptance Testing vs. Unit Testing: A Developers Perspective Owen Rogers Rob Styles
Advertisements

JUnit Tutorial Hong Qing Yu Nov JUnit Tutorial The testing problems The framework of JUnit A case study JUnit tool Practices.
xUnit Test Patterns (Some) xUnit Test Patterns (in practice) by Adam Czepil.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
CIT 590 Unit testing.
GoogleTest Primer. Outline Basic Concepts Assertions Basic Assertions Binary Comparison String Comparison Floating-Point Comparison Simple Tests Test.
Unit and Functional Testing with JUnit and Related Tools Greg Barnes University of Washington
TEST-DRIVEN DEVELOPMENT Lecture 3. Definition Test-driven development (development through testing) is a technique of programming, in which the unit tests.
PS4: Test Driven Development Based on Test Driven Development by Example By Kent Beck.
Well-behaved objects 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
20-Jun-15 XP Again. Test-Driven Development Advantages of writing tests first: Clarifies what the methods are supposed to do Methods are testable Methods.
24-Jun-15 JUnit. 2 Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (running whatever tests.
Writing a Unit test Using JUnit At the top of the file include: import junit.framework.TestCase; The main class of the file must be: public Must extend.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
George Blank University Lecturer. JUnit for Test Driven Development By Vivek Bhagat, George Blank.
 What is Software Testing  Terminologies used in Software testing  Types of Testing  What is Manual Testing  Types of Manual Testing  Process that.
Test-Driven Development “Test first, develop later!” –OCUnit.
JsUnit An introduction to unit testing in-browser JavaScript with JsUnit Edward Hieatt February, 2005 JsUnit.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
Test Driven Development TDD. Testing ”Testing can never demonstrate the absence of errors in software, only their presence” Edsger W. Dijkstra (but it.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
Lesson 7 Unit Testing /JUnit/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Unit and Functional Testing Your Flex Applications Mike Nimer Dir. Of Engineering nomee.com.
Software Development Software Testing. Testing Definitions There are many tests going under various names. The following is a general list to get a feel.
Intoduction to Unit Testing Using JUnit to structure Unit Testing SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick.
October, 2006 © Copyright 2006, Larry A. Beaty. Copying and distribution of this document is permitted in any medium, provided this notice is preserved.
Test Driven Development Arrange, Act, Assert… Awesome Jason Offutt Software Engineer Central Christian Church
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
A tool for test-driven development
Simple Java Unit Testing with JUnit 4 and Netbeans 6.1 Kiki Ahmadi JUG-Bonek.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Testing, Testing & Testing - By M.D.ACHARYA QA doesn't make software but makes it better.
JUnit A framework which provides hooks for easy testing of your Java code, as it's built Note: The examples from these slides can be found in ~kschmidt/public_html/CS265/Labs/Java/Junit.
Scalatest. 2 Test-Driven Development (TDD) TDD is a technique in which you write the tests before you write the code you want to test This seems backward,
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Testing Spring Applications Unit Testing.
JUnit A Unit Testing Framework for Java. The Objective Introduce JUnit as a tool for Unit Testing Provide information on how to: Install it Build a test.
(1) Test Driven Development Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
Unit Testing with FlexUnit
Testing JUnit Testing. Testing Testing can mean many different things It certainly includes running a completed program with various inputs It also includes.
PHPUnit Julia Bondar IAPM23. Agenda What is PHPUnit How to write an automated test Writing and running tests with PHPUnit Advantages and disadvantages.
Testing Unit Testing In Evergreen Kevin Beswick Laurentian University / Project Conifer.
Software engineering - 2 Section 8. QUIZ Show how it is possible to determine the height of a tall building with the aid of a barometer.
Introduction to Exceptions in Java CS201, SW Development Methods.
Unit testing with NUnit Anne Lam & Chris James CMPS 4113 – Software Engineering April 15, 2015.
Powerpoint Templates Page 1 Powerpoint Templates Unit Testing Ari Seppi
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Object Oriented Testing (Unit Testing)
Test-driven development
Smalltalk Testing - SUnit
Unit testing Java programs Using JUnit
Test Driven Development
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
Software engineering – 1
Software Engineering 1, CS 355 Unit Testing with JUnit
History, Characteristics and Frameworks
Selenium HP Web Test Tool Training
Conditions and Ifs BIS1523 – Lecture 8.
Test-driven development (TDD)
Testing and Test-Driven Development CSC 4700 Software Engineering
Presentation transcript:

Automated Testing with PHPUnit

How do you know your code works?

Manual Testing Type in a value Submit the form Check by eye

Manual Testing Tedious Time Consuming Error Prone Did you test everything? Consistently?

Automated Testing Have the computer run your tests

Pro: Confidence Know that your code does what it needs to Know that your code doesn’t break anything that used to work Regression Testing

Con: Testing isn’t free Writing tests takes time Response: So does manual testing Mo Code Mo Problems Response: It’s a worthwhile investment

Unit Testing Automated testing one unit at a time

What is a unit? Module (procedural programming) Class (OOP)

Breaking Down Unit Tests Test Suite composed of Test Case Classes each of which have Test Methods which make 1 or more Assertions

A Unit Test Asserts That A Unit Of Code Performs To A Specification

Help XUnit Frameworks

XUnit Frameworks Provide Assertions Calls Test Methods Help Setup Test Cases Test Runners

Assertions Code to verify that expected and actual values match Often methods starting with “assert…()” or “refute…()” Used by the developer $this->assertTrue() $this-> assertFalse() $this-> assertEquals()

Calls Test Methods Knows to call your code which tests a particular condition, method, or other “sub unit” Methods usually begin with “Test…()” Written by the developer class … { public function test…() { … }

Help setUp and tearDown Offers special functions that get called before and after each test. Written by the developer class … { public function setUp() {…} public function tearDown() {…} }

Unit Test Life Cycle TestCase:: setUp() TestCase:: test*() TestCase:: tearDown()

Test Case A class with test methods Usually offers assert methods Extended by the developer class MyTest extends PHPUnit_Framework_ TestCase { … }

Provide Test Runners Code that makes executing tests simple Often a command-line tool (useable by IDE)

Test First or Test Last?

Test First Test Driven Development (TDD)

Testing Cycle Write Test Confirm Test Fails Make Test Pass Ensure All Tests Pass

Find Problems Early How should your code work? What do the requirements mean?

Manage Scope Creep Do The Simplest Thing That Could Possibly Work YAGNI Know when you’re done: All tests are green.

Test Last Problematic Tests become biased for the code you already wrote

What don’t you test?

Don’t Test the Language/Framework Don’t test session session initiaiton Or $_POST/$_GET/etc. Or anything provided by PHP (and/or your framework, $_POST[“loggedIn”] = true; $this-> assertTrue($_POST [“loggedIn”]) # Wrong!

Don’t Test Methods Without Logic class … { private $foo; public get_foo() { return $this->foo; }

What to Test

Boundaries function … { if ($foo > 3) { // test whether execution goes in here } else { // test whether execution goes in here }

Invalid values 0 Negative values Empty strings Very long strings (>500chars)

What’s a good test? Repeatable Use setUp() to make sure everything is right for your test Independent Use tearDown() to clean up Thorough It’s ok to have more than one test method in your case… in fact it’s often necessary!