CSE 403 JUnit Reading: These lecture slides are copyright (C) Marty Stepp, 2007. They may not be rehosted, sold, or modified without expressed permission.

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.
2/18/2008ITK 1681 Feb. 20, Wed. 8:00 – 9:30 pm STV Closed book, notes, and no computer is allowed. 2.Everyone is allowed to bring a self- prepared.
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.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
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.
UML Sequence Diagrams Reading: UML Distilled Ch. 4, by M. Fowler
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
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.
Object-Oriented Software Engineering, Ch. 9
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.
1 Building Java Programs Chapter 7: Arrays These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold, or.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
A tool for test-driven development
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.
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.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Unit Testing in Eclipse Presented by David Eisler 08/09/2014.
Reasoning and Design (and Assertions). How to Design Your Code The hard way: Just start coding. When something doesn’t work, code some more! The easier.
 2016, Marcus Biel, Marcus Biel, Software Craftsman Identity vs Equality in Java
Test automation / JUnit Building automatically repeatable test suites.
Lecture 5: Test-Driven Development Basics
Building Java Programs
Dept of Computer Science University of Maryland College Park
Introduction to JUnit CS 4501 / 6501 Software Testing
Midterm Review Problems
Defining New Types of Objects, part 3
JUnit 28-Nov-18.
JUnit 28-Nov-18.
Introduction to JUnit CS 4501 / 6501 Software Testing
SWE 619 Software Construction Last Modified, Fall 2015 Paul Ammann
Lecture 5: For Loops Building Java Programs: A Back to Basics Approach
Test Driven Development
Solving Equations and Inequalities with Absolute Value
CSE 142 Lecture Notes Defining New Types of Objects
Building Java Programs
Java Classes and Objects 4th Lecture
CSE 403 Scheduling These lecture slides are copyright (C) Marty Stepp, 2007, with significant content taken from slides written by Valentin Razmov. They.
What's next? Should you major in Computer Science?
Section 4: Graphs and Testing
IMPORTANT NOTE Some parts of these section slides deal with null ints. This was a mistake, as primitives cannot be null. These issues have been corrected.
An Introduction to Linux
Test Driven Development
Suggested self-checks: Section 7.11 #1-11
Integration Reading: McConnell, Code Complete, Ch. 29
CSE 143 Lecture 5 More ArrayIntList:
CSE 142 Lecture Notes Defining New Types of Objects, cont'd.
slides created by Marty Stepp
JUnit Reading: various web pages
TCSS 360, Spring 2005 Lecture Notes
CS-1020 and Exception Handling
Suggested self-checks: Section 7.11 #12-29
slides adapted from Marty Stepp
Junit Tests.
slides created by Marty Stepp
Presentation transcript:

CSE 403 JUnit Reading: These lecture slides are copyright (C) Marty Stepp, 2007. They may not be rehosted, sold, or modified without expressed permission from the author. All rights reserved.

JUnit and Eclipse Adding JUnit to an Eclipse project: click Project -> Properties -> Add External JARs... -> eclipse folder/plugins/org.junit_x.x.x/junit.jar Create the test case click File -> New -> JUnit Test Case or right-click a file and choose New Test

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