JUnit test and Project 3 simulation. 2 JUnit The testing problems The framework of JUnit A case study Acknowledgement: using some materials from JUNIT.

Slides:



Advertisements
Similar presentations
JUnit Tutorial Hong Qing Yu Nov JUnit Tutorial The testing problems The framework of JUnit A case study JUnit tool Practices.
Advertisements

Java Testing Tools. junit is a testing harness for unit testing. emma is a code coverage tool. The tools can be used in concert to provide statement and.
1 Unit Testing with JUnit CS 3331 Fall 2009 Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report, 3(7):37-50, Available.
J-Unit Framework.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
An Introduction to JUnit Greg Jackson June Software Quality Assurance & Testing 2 Contact Info Northrop Grumman Corp
T ESTING WITH J UNIT IN E CLIPSE Farzana Rahman. I NTRODUCTION The class that you will want to test is created first so that Eclipse will be able to find.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
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
Fall 2007CS 2251 Programming Tools Eclipse JUnit Testing make and ant.
JUnit. What is unit testing? A unit is the smallest testable part of an application. A unit test automatically verifies the correctness of the unit. There.
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.
20-Jun-15 More About JUnit. Test suites A test suite is a group of JUnit tests You can create a test suite in Eclipse as follows: File  New  Other...
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.
JUnit Introduction and Advanced Features. Topics Covered  Junit Introduction  Fixtures  Test Suites  Currency Example.
26-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.
CS 635 Advanced Object-Oriented Design & Programming Spring Semester, 2006 Doc 2 Terms & Testing Jan 24, 2006 Copyright ©, All rights reserved SDSU.
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.
13-Jul-15 Test Suites. Test classes A unit test is a test of an individual class By convention, we name test classes after the class that is being tested.
14-Jul-15 JUnit 4. Comparing JUnit 3 to JUnit 4 All the old assertXXX methods are the same Most things are about equally easy JUnit 4 makes it easier.
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.
JUnit test and Project 3 simulation. Midterm Exam Wednesday, March 18, 2009 Content: Week 1 to Week 9 Guideline: posted on D2L. Format: Multiple choices.
Programmer Testing Testing all things Java using JUnit and extensions.
© 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.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
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.
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.
Recursion. Midterm Exam Wednesday,November 4, 2009 Content: Week 1 to Week 9 Guideline: posted on D2L. Format: Multiple choices Simple problem solving.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
JUnit Dwight Deugo Nesa Matic
ESO - Garching 23 June – 02 July, 2003 ACS Course JUnit for Java Unit Testing H. Sommer.
JUnit Dwight Deugo Nesa Matic
A tool for test-driven development
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.
JUnit. Introduction JUnit is an open source Java testing framework used to write and run repeatable tests JUnit is integrated with several IDEs, including.
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.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
Test a Little, Code a Little Colin Sharples IBM Global Services New Zealand Colin Sharples IBM Global Services New Zealand.
JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.
SE 433/333 Software Testing & Quality Assurance Dennis Mumaugh, Instructor Office: CDM, Room 428 Office Hours: Tuesday, 4:00 –
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
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.
Topic: Junit Presenters: Govindaramanujam, Sama & Jansen, Erwin.
JUnit Tatiana Totskaya. Main parts of the presentation  Unit Testing  JUnit – Main Concepts  JUnit Primer  Unit Testing in Eclipse Using JUnit.
CSE 143 Lecture 14: testing.
Software Construction Lab 10 Unit Testing with JUnit
JUnit Automated Software Testing Framework
Computer Science 209 Testing With JUnit.
Overview of Eclipse Lectures
JUnit Automated Software Testing Framework
JUnit 28-Nov-18.
Credit to Eclipse Documentation
Unit Testing with JUnit
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.
Chapter 20: Software Testing - Using JUnit, and Cobertura
JUnit Tutorial Hong Qing Yu Nov 2005.
Presentation transcript:

JUnit test and Project 3 simulation

2 JUnit The testing problems The framework of JUnit A case study Acknowledgement: using some materials from JUNIT tutorial by Hong Qing Yu (

3 The Testing Problems programmers Should write few Do Why? I am so busy It is difficult

4 The Testing Problems Programmers need such kind of tool: “Writing a few lines of code, then a test that should run, or even better, to write a test that won't run, then write the code that will make it run.” JUnit is that kind of tool!

5 JUnit The testing problems The framework of JUnit A case study

6 The Framework of JUnit

7 JUnit The testing problems The framework of JUnit A case study

8 A Case Study Lab3Queue: enQueue method deQueue method

Include junit library in eclipse 9

10 How to Write A TestCase using Junit (available in Eclipse 3.1 or later) Step 1:Create a JUNIT test case (File -> New -> Junit Test Case

Create a test case 11

Create a test case import junit.framework.*; public class Lab3QueueTest { public void setUp() throws Exception { } public void tearDown() throws Exception { } 12

Create a test case import junit.framework.*; public class Lab3QueueTest extends TestCase { Lab3Queue testQueue; int queueSize; public void setUp() throws Exception { testQueue = new Lab3Queue(); queueSize = testQueue.getSize(); } public void tearDown() throws Exception { } 13

Create a test case For each method that you are going to test: Write a corresponding test method named: test in the test case 14

Create a test case public void testenQueue() { int newItem = 1; queueSize = testQueue.getSize(); testQueue.enQueue(newItem); Assert.assertEquals(queueSize+1, testQueue.getSize()); int actualItem = ((Integer) testQueue.getLastNode()).intValue(); Assert.assertEquals(newItem, actualItem); } 15

16 Assert assertEquals(expected, actual) assertEquals(message, expected, actual) assertEquals(expected, actual, delta) assertEquals(message, expected, actual, delta) assertFalse(condition) assertFalse(message, condition) Assert(Not)Null(object) Assert(Not)Null(message, object) Assert(Not)Same(expected, actual) Assert(Not)Same(message, expected, actual) assertTrue(condition) assertTrue(message, condition)

17 Structure setUp() Storing the fixture's objects in instance variables of your TestCase subclass and initialize them by overriding the setUp method tearDown() Releasing the fixture’s

Writing a test suite Step 2: Create a test suite by choosing 18

Writing a test suite 19

Writing a test suite import junit.framework.Test; import junit.framework.TestSuite; public class AllTests { public static Test suite() { TestSuite suite = new TestSuite("Test for AiportSimulation"); //$JUnit-BEGIN$ suite.addTestSuite(Lab3QueueTest.class); //$JUnit-END$ return suite; } 20

Running a test 21 AllTests -> choose Run -> Run As -> Junit Test

Running a test 22

23 Design Test Cases The real world scenarios The number boundaries

24 Tips Testcases must extend TestCase All ‘test’ methods must include at least one call to an assert method or to fail: assertEquals (String message,...) assertNotNull (String message, Object obj) assertNull (String message, Object obj) assertSame (String message, Obj exp, Obj actual) assertTrue (String message, boolean condition) fail (String message) Remove System.out.println after test cases are working and rely on Junit assert methods to determine success/failure.

25 Dynamic Run Since JUnit 2.0 there is an even simpler dynamic way. You only pass the class with the tests to a TestSuite and it extracts the test methods automatically. suite.addTestSuite(Lab3QueueTest.class);

Project 3 - Algorithm 26