Joel Adams and Jeremy Frens Calvin College

Slides:



Advertisements
Similar presentations
Unit Testing Australian Development Centre Brisbane, Australia.
Advertisements

J-Unit Framework.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
Approach of Unit testing with the help of JUnit Satish Mishra
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
JUnit Syed Nabeel. Motivation Unit Testing Responsibility of  developer Rarely done properly Developers Excuse: “I am too much in a hurry”
JUnit, Revisited 17-Apr-17.
JUnit Introduction and Advanced Features. Topics Covered  Junit Introduction  Fixtures  Test Suites  Currency Example.
22-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.
JUnit. Why is testing good? Due to psychological factors, programmers are bad testers. A computer can test much faster than a human Philosophy: “If it.
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.
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.
TDD Test-Driven Development. JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to.
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.
1 CSC/ECE 517 Fall 2010 Lec. 2 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Debugging 5.Testing.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
Unit Testing Discussion C. Unit Test ● public Method is smallest unit of code ● Input/output transformation ● Test if the method does what it claims ●
George Blank University Lecturer. JUnit for Test Driven Development By Vivek Bhagat, George Blank.
1 CS115 Class 15: Testing Due today –User Manual –Software Inspections –Review: Testing Next time –Review No Silver Bullet.
Programmer Testing Testing all things Java using JUnit and extensions.
19-Aug-15 JUnit tests for output. Capturing output System.out.print and System.out.println usually “print” to the screen, but you can change that OutputStream.
© 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.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Principles of Object Oriented Programming Practical session 2 – part A.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Testing in Extreme Programming
1 Object Oriented Programming Testing with Unit Testing & the JUnit tool Basic Refactoring techniques.
CSC 216/001 Lecture 4. Unit Testing  Why is it called “unit” testing?  When should tests be written?  Before the code for a class is written.  After.
JUnit & Eclipse1 DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY Feb 2, 2009 revision 1.2 – Feb 2, 2009 by Emil Vassev & Joey.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
JUnit Dwight Deugo Nesa Matic
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
JUnit Dwight Deugo Nesa Matic
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
A tool for test-driven development
Simple Java Unit Testing with JUnit 4 and Netbeans 6.1 Kiki Ahmadi JUG-Bonek.
Week81 APCS-AB: Java Unit Testing Information today from “Unit Testing in BlueJ” October 28, 2005.
JUnit Jumpstart © Manning Publications.
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
JUnit Don Braffitt Updated: 10-Jun-2011.
JUnit Eclipse, Java and introduction to Junit. Topics Covered  Using Eclipse IDE  Example Java Programs  Junit Introduction.
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.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
1 CSC 216 Lecture 3. 2 Unit Testing  The most basic kind of testing is called unit testing  Why is it called “unit” testing?  When should tests be.
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.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.
1 JUnit. 2 Unit Testing with JUnit If code has no automated test case written for it to prove that it works, it must be assumed not to work. An API that.
PHPUnit Julia Bondar IAPM23. Agenda What is PHPUnit How to write an automated test Writing and running tests with PHPUnit Advantages and disadvantages.
Test automation / JUnit Building automatically repeatable test suites.
Getting Started with JUnit Getting Started with JUnit The benefits and ease of writing and running JUnit test cases and test suites. The benefits and ease.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Software Construction Lab 10 Unit Testing with JUnit
Don Braffitt Updated: 26-Mar-2013
Dept of Computer Science University of Maryland College Park
JUnit Automated Software Testing Framework
Introduction to JUnit CS 4501 / 6501 Software Testing
Unit testing Java programs Using JUnit
Computer Science 209 Testing With JUnit.
Software Engineering 1, CS 355 Unit Testing with JUnit
Overview of Eclipse Lectures
JUnit Automated Software Testing Framework
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to JUnit IT323 – Software Engineering II
JUnit SWE 619 Spring 2008.
JUnit Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from the Eclipse 3.0 and.
JUnit Tutorial Hong Qing Yu Nov 2005.
Principles of Object Oriented Programming
Presentation transcript:

Joel Adams and Jeremy Frens Calvin College Unit Testing Joel Adams and Jeremy Frens Calvin College

Test-First Development Test-first development stresses the use of tests in developing software: Tests must be easy to write. Tests must be automatic. Tests must be fast. Tests must be written first. Tests must be easy to add.

Types of Testing Unit-testing tests the individual units (i.e., methods) of a program. Functional testing tests the interaction of these units.

JUnit JUnit is a open-source unit-testing framework for Java. Written by Erich Gamma and Kent Beck as part of their development of eXtreme Programming. Uses two technologies to make testing easier: inheritance reflection

Test Case Class public class EmployeeTest extends junit.framework.TestCase { // define instance variables // set up method // test methods } TestCase implements the code to automatically run the tests. The instance variables are your choice. The setup method sets up values for your instance variables. The test methods do the testing.

The Setup Method Must have this signature. protected void setUp() { super.setUp(); // initialize instance variables } Must have this signature. Code should initialize your instance variables. This method is called just before each test method.

A Test Method All test methods must have this signature. public void testSomething() { // run your tests } All test methods must have this signature. Replace Something with a more descriptive name. The test runners automatically find the test methods. Test methods can throw exceptions (considered a failed test).

Assertions TestCase provides several methods for implementing the tests: assertEquals(expected, computed); assertEquals(expected, computed, epsilon); assertTrue(booleanExpression); assertFalse(booleanExpression); assertNull(referenceExpression); fail(); Each of these methods has an optional String parameter for an output label.

Running Your Tests From the command line: junit.textui.TestRunner for textual output. junit.swingui.TestRunner for GUI output (automatically reloads classes after compilation). Within an IDE: Set up IDE to run one of the command-line interfaces. Use a JUnit plug-in.

Interpreting the Results “My code green barred.” The GUIs use a green bar to indicate successful tests. CLIs just print “Ok”. “My code red barred.” A red bar indicates that a test failed---a failed assertion or a thrown exception. JUnit gives you a stack trace to help in debugging.

Example public class EmployeeTest extends TestCase { private Employee myEmployee1; public void setUp() { myEmployee1 = new Employee(“X”, 5.44); } public void testPaycheck() { assertEquals( 282.88, myEmployee1.getPaycheck(48), 1e-3); …

Example … public void testBadEmployees() { try { new Employee(“”, 5); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage() .matches(“name”); } // etc…