Software Engineering 1, CS 355 Unit Testing with JUnit

Slides:



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

J-Unit Framework.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Unit and Functional Testing with JUnit and Related Tools Greg Barnes University of Washington
1-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.
Approach of Unit testing with the help of JUnit Satish Mishra
Cell phones off Name signs out – congrats Sean! CSE 116 Introduction to Computer Science for Majors II1.
Introduction to Eclipse, Unit Testing and JUnit David Rabinowitz.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
JUnit, Revisited 17-Apr-17.
21-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.
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.
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.
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.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Unit Testing.
Class Library, Formatting, Wrapper Classes, and JUnit Testing
Testing in Extreme Programming
1 Testing With The JUnit Framwork Carl-Fredrik Sørensen, PhD Fellow
Sadegh Aliakbary Sharif University of Technology Spring 2012.
Unit testing Unit testing TDD with JUnit. Unit Testing Unit testing with JUnit 2 Testing concepts Unit testing Testing tools JUnit Practical use of tools.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
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.
CSC 395 – Software Engineering Lecture 10: Execution-based Testing –or– We can make it better than it was. Better...faster...agiler.
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
Week81 APCS-AB: Java Unit Testing Information today from “Unit Testing in BlueJ” October 28, 2005.
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,
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
JUnit SWE 619 Summer July 18, 2007 SWE 619 (c) Aynur Abdurazik 2 What is JUnit? Open source Java testing framework used to write and run repeatable.
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.
Software Design– Unit Testing SIMPLE PRIMER ON Junit Junit is a free simple library that is added to Eclipse to all automated unit tests. The first step,
Testing JUnit Testing. Testing Testing can mean many different things It certainly includes running a completed program with various inputs It also includes.
13-Mar-16 Scalatest. Scalatest variants Scalatest is a testing framework inspired by JUnit Scalatest comes in various styles: FunSuite, FlatSpec, FunSpec,
Test automation / JUnit Building automatically repeatable test suites.
Automated Testing with PHPUnit. How do you know your code works?
Software Engineering 1 Object-oriented Analysis and Design Applying UML and Patterns An Introduction to Object-oriented Analysis and Design and Iterative.
CSE 143 Lecture 14: testing.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Software Construction Lab 10 Unit Testing with JUnit
Testing Tutorial 7.
Dept of Computer Science University of Maryland College Park
JUnit Automated Software Testing Framework
CSIS 3701: Advanced Object Oriented Programming
Introduction To Repetition The for loop
Introduction to JUnit CS 4501 / 6501 Software Testing
Computer Science 209 Testing With JUnit.
Algorithm and Ambiguity
Test-first development
JUnit Automated Software Testing Framework
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Introduction to Testing, SUnit and Error Handling
Test-driven development (TDD)
Testing and Test-Driven Development CSC 4700 Software Engineering
Introduction to JUnit CS 4501 / 6501 Software Testing
Test-Driven Development
Advanced Programming Behnam Hatami Fall 2017.
Introduction to JUnit IT323 – Software Engineering II
Algorithm and Ambiguity
Testing 24-Feb-19.
CS 240 – Advanced Programming Concepts
CSE 143 Lecture 5 More ArrayIntList:
Test-Driven Development
Joel Adams and Jeremy Frens Calvin College
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.
Presentation transcript:

Software Engineering 1, CS 355 Unit Testing with JUnit UWEC Department of Computer Science Introduction to Object Oriented Programming Software Engineering 1, CS 355 Unit Testing with JUnit CS 245

Types of Testing Unit testing – test each unit separately Integration testing – test whole system with units working together Regression testing – test to make sure additions haven’t broken anything Others…

Focus on Unit Testing Want to ensure each Java class that we create works as advertised In past courses, we have primarily tested by creating a “driver” program in the main method of the class Problems with this approach tend not to be complete in testing tend to test at end of coding testing code integrated with class code better to have it separate for design reasons

JUnit – A Framework for Unit Testing in Java JUnit - an open-source project to provide a better solution for unit testing in Java Integrates with many Java IDEs, including Eclipse Central idea: create a separate Java testing unit (usually a class) for each class you’re creating, then provide a means to easily integrate the testing unit with the tested class for unit testing

How JUnit Works Assume class Foo Test class must be named FooTest append string “Test” at end Test class must extend (inherit from) junit.framework.TestCase class e.g. import junit.framework.TestCase; … public class FooTest extends TestCase …

How JUnit Works (2) Where does the TestCase class come from? Answer: junit.jar Must add the junit.jar file to your project Java Build Path if not already present

How JUnit Works (3) One approach: the test class should contain a test method for each named public method in the original class Note: if multiple constructors, can just have one constructor test method JUnit does not support testing non-public methods Each test method should be named in the format: testOriginalMethod, with first lower case letter capitalized e.g. Foo constructor -> testFoo() e.g. Foo toString -> testToString()

How JUnit Works (4) How to execute the test class given that there’s no main method? Execute as a JUnit Test Run As/JUnit Test Most environments, including Eclipse, have JUnit plugins or modules to display the results graphically

JUnit Simple Example IsoDate class IsoDateTest class IsoDate.java IsoDateTest.java

JUnit Test Case Methods Note that JUnit uses “assertions” Assertions are boolean statements that claim that something is true about the code at a particular point Can test for: equality sameness null-ness truth or falsehood

JUnit Test Case Methods (2) assertEquals(primitiveExpected, primitiveActual) assertEquals(objectExpected, objectActual) assertSame(objectExpected, objectActual) assertNotSame(objectExpected, objectActual) assertNull(object) assertNotNull(object) assertTrue(boolean condition) assertFalse(boolean condition) e.g. assertEquals(0, epoch.getTime());

JUnit Test Results Two types of problems when running tests Failures – an assertion failed Failure results displayed Expected and result value displayed in trace Errors – a problem with the Java code Try to make sure you have “solid” code, don’t raise any exceptions/errors

Value of Testing In the past, software developers have often put too little energy into testing Testing frameworks like JUnit make testing easier, allow automation, and make it more likely that your code works correctly “When the bar is green, your code is clean.” – saying from the JUnit developers Not always true, but it’s a step in the right direction

Test Driven Development More recent approach Generated from Agile Software Development processes Repeat Develop a test case that meets one requirement (test will of course fail) Write the code to make that test succeed Refactor (redesign) the code to ensure good design Until software is fully developed