TCSS 360, Spring 2005 Lecture Notes

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

J-Unit Framework.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
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.
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
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.
Copyright W. Howden1 Lecture 13: Programming by Contract.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
Fall 2007CS 2251 Programming Tools Eclipse JUnit Testing make and ant.
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.
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.
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.
AP Computer Science.  Not necessary but good programming practice in Java  When you override a super class method notation.
15-Jul-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 (testing whatever occurs.
George Blank University Lecturer. JUnit for Test Driven Development By Vivek Bhagat, George Blank.
CS 106 Introduction to Computer Science I 04 / 30 / 2010 Instructor: Michael Eckmann.
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.
Data Objects (revisited) Recall that values are stored in data objects, and that each data object holds one value of a particular type. Data objects may.
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 Bartosz Walter Software Engineering Lecture XXX.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
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.
Test automation / JUnit Building automatically repeatable test suites.
JUnit test and Project 3 simulation. 2 JUnit The testing problems The framework of JUnit A case study Acknowledgement: using some materials from JUNIT.
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
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.
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.
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Practice Session 5 Java: Packages Collection Classes Iterators Generics Default Methods Anonymous Classes Generic Methods Lambdas Design by Contract JUnit.
Unit Testing in Eclipse Presented by David Eisler 08/09/2014.
Test automation / JUnit Building automatically repeatable test suites.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Advanced programming Practices
Lecture 5: Test-Driven Development Basics
Dept of Computer Science University of Maryland College Park
Introduction to JUnit CS 4501 / 6501 Software Testing
More JUnit CS 4501 / 6501 Software Testing
Abstraction Functions and Representation Invariants
Test-first development
JUnit 28-Nov-18.
JUnit 28-Nov-18.
Introduction to JUnit CS 4501 / 6501 Software Testing
JUnit 7-Dec-18.
Building Java Programs
JUnit 11-Jan-19.
Defining Classes and Methods
Introduction to JUnit IT323 – Software Engineering II
Test Driven Development
CSE 403 JUnit Reading: These lecture slides are copyright (C) Marty Stepp, They may not be rehosted, sold, or modified without expressed permission.
Testing 24-Feb-19.
Advanced programming Practices
Section 4: Graphs and Testing
Test Driven Development
Data Structures & Algorithms
JUnit 18-Apr-19.
JUnit Reading: various web pages
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 31-May-19.
Junit Tests.
Presentation transcript:

TCSS 360, Spring 2005 Lecture Notes JUnit Testing Relevant Reading: Test Infected: Programmers Love Writing Tests

JUnit and Eclipse Adding JUnit to your Eclipse project: click Project -> Properties -> Add External JARs... -> eclipse folder/plugins/org.junit_3.8.1/junit.jar Create the test case junit.framework.TestCase implements Test click File -> New -> JUnit Test Case

JUnit TestCase methods public void setUp() run at start of each test public void tearDown() run at end of each test public YourClassName () // constructor run once at start of ALL tests (when testing object is created)

JUnit TestCase assertions testing methods (name of method MUST start with 'test') Formatting key: optional can be any type (primitive or Object) public void assertEquals(String message, Object expected, Object actual) note: no Assert. required public void assertFalse(String message, boolean condition) public void assertNotEquals(String message, Object expected, Object actual) public void assertNotNull(String message, Object obj) public void assertNotSame(String message, Object expected, Object actual) uses ==, not .equals public void assertSame(String message, Object expected, Object actual) public void assertTrue(String message, boolean condition) public void fail(String message)

JUnit exercise Using our Date class, let's: Enforce a contract with invariants on our Date objects, so that they can never hold an invalid state. Write an addDays method that takes an int and adjusts the current Date's date by the given number of days forward in time. If the argument is negative, go backward in time. Write a compareTo method that compares Dates chronologically. Write an equals method that tells whether two Dates store the same date. Write getDaysFrom that takes another Date object and returns the number of days this Date is away from the date of the given other Date object. (It is therefore implied that after a call of this.addDays(-this.getDaysFrom(other)), the statement this.equals(other) would be true.) Write JUnit test code that checks each of the above methods for correctness. Utilize intelligent testing techniques as presented in class. a good equals method has some initial checks like checking for null, checking whether this == that, check instanceof, etc... then it calls compareTo