JUnit Testing Why we do this and how we can get better.

Slides:



Advertisements
Similar presentations
+ Introduction to JUnit IT323 – Software Engineering II By: Mashael Al-Duwais 1.
Advertisements

Here’s what we see when we start a new BlueJ “Project”. BlueJ automatically creates a small “readme.txt” file to hold any directions we wish to write about.
Practice Session 5 Java: Packages Collection Classes Iterators Generics Design by Contract Test Driven Development JUnit.
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.
Computer Science 209 Testing With JUnit. Why Test? I don ’ t have time, I ’ ve got a deadline to meet The more pressure I feel, the fewer tests I will.
J-Unit Framework.
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.
Unit and Functional Testing with JUnit and Related Tools Greg Barnes University of Washington
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.
Fall 2007CS 2251 Programming Tools Eclipse JUnit Testing make and ant.
CS 635 Advanced Object-Oriented Design & Programming Spring Semester, 2006 Doc 2 Terms & Testing Jan 24, 2006 Copyright ©, All rights reserved SDSU.
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.
JAVA LIBRARY CLASSES CITS Main concepts to be covered Using library classes: String, Math, Color Reading documentation Java 7 API is available.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
From BlueJ to NetBeans SWC 2.semester.
CS/ENGRD 2110 SPRING 2015 Lecture 3: Fields, getters and setters, constructors, testing 1.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Class Library, Formatting, Wrapper Classes, and JUnit Testing
Week 3 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
ANDROID – TESTING L. Grewe. With the AndroidStudio IDE.
Intoduction to Unit Testing Using JUnit to structure Unit Testing SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
JUnit test and Project 3 simulation. 2 JUnit The testing problems The framework of JUnit A case study Acknowledgement: using some materials from JUNIT.
First BlueJ Day Houston, 2006 Unit Testing with BlueJ Bruce Quig Deakin University.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
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.
Java Methods Methods contain a group of instructions that together perform a single task. For example if I want to perform the task of “making a pizza”,
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
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,
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
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.
CS2 Module 26 Category: OO Concepts Topic: Interfaces Objectives –Interfaces.
Unit Testing with FlexUnit
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
CS/ENGRD 2110 FALL 2013 Lecture 3: Fields, getters and setters, constructors, testing 1.
Today protected access modifier Using the debugger in Eclipse JUnit testing TDD Winter 2016CMPE212 - Prof. McLeod1.
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
CSE 143 Lecture 14: testing.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Lecture 5: Test-Driven Development Basics
JUnit testing framework
More Sophisticated Behavior
Dept of Computer Science University of Maryland College Park
Computer Science 209 Testing With JUnit.
CMPE212 – Stuff… Assn 2 due this Friday. Winter 2018
Test-driven development (TDD)
Credit to Eclipse Documentation
Introduction to JUnit CS 4501 / 6501 Software Testing
Fall 2018 CISC124 12/3/2018 CISC124 or talk to your grader with questions about assignment grading. Fall 2018 CISC124 - Prof. McLeod Prof. Alan McLeod.
Unit Testing with JUnit
Introduction to JUnit IT323 – Software Engineering II
Fall 2018 CISC124 2/1/2019 CISC124 Note that the next assignment, on encapsulation, is due next Wednesday at 7pm – not Friday. The next Quiz is not until.
CMPE212 – Reminders Assignment 2 due this Friday.
CSE 143 Lecture 5 More ArrayIntList:
CMPE212 – Reminders Assignment 2 due this Friday.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

JUnit Testing Why we do this and how we can get better

What is JUnit JUnit testing is an extension to Java JUnit testing is an extension to Java It is a very powerful way to unit test our projects It is a very powerful way to unit test our projects Unit testing allows us to test the individuals pieces of our code Unit testing allows us to test the individuals pieces of our code At the method level, the class level and even the package level At the method level, the class level and even the package level

Why do we do this We use JUnit testing so we can perform regression testing. We use JUnit testing so we can perform regression testing. Regression testing is retesting after a change has been made. Regression testing is retesting after a change has been made. It is not uncommon to fix a bug in your code only to have more bugs show up. It is not uncommon to fix a bug in your code only to have more bugs show up. With regression testing and JUnit we have an easy way to specify tests and run and rerun them as we modify our code. With regression testing and JUnit we have an easy way to specify tests and run and rerun them as we modify our code.

How to go about testing It is true in fact that you can set your test classes up before you even write your other classes. It is true in fact that you can set your test classes up before you even write your other classes. You should be able to read the API and get a picture of what the classes are supposed to do. You should be able to read the API and get a picture of what the classes are supposed to do. You should then be able to write tests that will succeed if the methods behave correctly and fail otherwise. You should then be able to write tests that will succeed if the methods behave correctly and fail otherwise.

Writing a test class A JUnit test class is an actual Java class. A JUnit test class is an actual Java class. It has a couple of extra pieces, but BlueJ puts all the extra stuff for you. It has a couple of extra pieces, but BlueJ puts all the extra stuff for you. A test class is a special kind of class, it is a JUnit.framework.TestClass class. A test class is a special kind of class, it is a JUnit.framework.TestClass class. You can see this in BlueJ. You can see this in BlueJ. Because a test class is one of these special classes it has access to a lot of methods. Because a test class is one of these special classes it has access to a lot of methods.

Helpful methods These test classes have a lot of different methods that they can use. These test classes have a lot of different methods that they can use. The method all look more or less the same, they simply differ by the parameters. The method all look more or less the same, they simply differ by the parameters. We know this as overloading We know this as overloading The most common method is: assertEquals The most common method is: assertEquals Which says the two parameters are equal Which says the two parameters are equal

AssertEquals AssertEquals comes in about as many different flavors as there are types AssertEquals comes in about as many different flavors as there are types It can compare Strings, ints, double, objects, etc. It can compare Strings, ints, double, objects, etc. This is the method we use most often This is the method we use most often

Other Methods AssertNull AssertNull AssertNotNull AssertNotNull AssertNotEquals AssertNotEquals AssertSame AssertSame AssertTrue AssertTrue AssertFalse AssertFalse

Writing test classes You can and should actually open up and take a look at the test classes you write You can and should actually open up and take a look at the test classes you write Even if you write them using the BlueJ interface. Even if you write them using the BlueJ interface. There will be times when you cannot get what you want accomplished using the BlueJ interface and you will have to open the file. There will be times when you cannot get what you want accomplished using the BlueJ interface and you will have to open the file. You will want to get comfortable with what is in those files. You will want to get comfortable with what is in those files.

References You can find a lot of information on the web about Junit testing You can find a lot of information on the web about Junit testing Their website can be found at: Their website can be found at: There documentation about their classes can be found: ndex.htm There documentation about their classes can be found: ndex.htm ndex.htm ndex.htm