Unit Testing in Eclipse Presented by David Eisler 08/09/2014.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
Unit Testing. Topics Motivation JUnit framework Basic JUnit tests – static methods Ensure exceptions – instance methods.
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.
Ch. 2 Exploring core JUnit. This chapter covers ■ Using the core JUnit classes ■ Understanding JUnit mechanisms ■ Understanding the JUnit lifecycle.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
JUnit. Why is testing good? Due to psychological factors, programmers are bad testers. A computer can test much faster than a human Philosophy: “If it.
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.
TDD Test-Driven Development. JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to.
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.
Options for User Input Options for getting information from the user –Write event-driven code Con: requires a significant amount of new code to set-up.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
Software Development Tools
INF 111 / CSE 121 Discussion Session Week 2 - Fall 2007 Instructor: Michele Rousseau TA: Rosalva Gallardo.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Unit Testing.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved. Slides Prepared.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Testing. RHS – SOC 2 Testing So far, we have not really created tests in a systematic manner Testing has been more like ”probing” Making a thorough test.
GIT and JUnit Dr. Andrew Wallace PhD BEng(hons) EurIng
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
Test automation / JUnit Building automatically repeatable test suites.
SVN in Eclipse Presented by David Eisler 10/09/2014.
Testing in NetBeans. SWC Testing The ideal test: When the test is passed, the product is ready for delivery! Ideal – but (almost) impossible –Number of.
JUnit test and Project 3 simulation. 2 JUnit The testing problems The framework of JUnit A case study Acknowledgement: using some materials from JUNIT.
CSC 395 – Software Engineering Lecture 10: Execution-based Testing –or– We can make it better than it was. Better...faster...agiler.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
Chapter 11, Testing: Unit Testing with JUnit 4
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
JUnit Adam Heath. What is JUnit?  JUnit is a unit testing framework for the Java programming language  It allows developers to swiftly and easily test.
A tool for test-driven development
Tool Install How to download & install Java 6 & Eclipse updated version based on Dr. G. L. Ray’s slides.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
JUnit. Introduction JUnit is an open source Java testing framework used to write and run repeatable tests JUnit is integrated with several IDEs, including.
Test it! Unit, mocking and in-container Meet Arquillian! Ivan St. Ivanov.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
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 in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved.
CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Unit Testing. F-22 Raptor Fighter Manufactured by Lockheed Martin & Boeing How many parts does the F-22 have?
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.
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,
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Today protected access modifier Using the debugger in Eclipse JUnit testing TDD Winter 2016CMPE212 - Prof. McLeod1.
Test automation / JUnit Building automatically repeatable test suites.
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
Unit Testing.
Software Construction Lab 10 Unit Testing with JUnit
Unit Testing with JUnit
Dept of Computer Science University of Maryland College Park
Introduction to JUnit CS 4501 / 6501 Software Testing
This presentation is created for the course COP4331 at UCF
Junit with.
JUnit 28-Nov-18.
Introduction to JUnit IT323 – Software Engineering II
Test Driven Development
Section 3 Graphs & Testing
CSE 403 JUnit Reading: These lecture slides are copyright (C) Marty Stepp, They may not be rehosted, sold, or modified without expressed permission.
CS 240 – Advanced Programming Concepts
Section 4: Graphs and Testing
JUnit Reading: various web pages
TCSS 360, Spring 2005 Lecture Notes
Junit Tests.
Presentation transcript:

Unit Testing in Eclipse Presented by David Eisler 08/09/2014

Agenda  Pre-Requirements  Unit Testing  JUnit  Multiply Demo  For a more comprehensive overview of Junit in Eclipse see: e.html e.html

Pre-Requirements  Eclipse. I am using Eclipse Standard 4.4 (Luna) for 64 bit version in this tutorial.  You can download Eclipse at:  Eclipse will run on most Windows and Linux OS’s (See previous link)

What is Unit Testing  Testing bits of code in isolation with test code.

Why Do We Care about Unit Testing?  Regression testing  Allows you to make big changes to code quickly with confidence.  Documented proof of testing.  Ultimate goal is to save time and money in the long run by catching bugs sooner.

Cons of Unit Testing  All code is subject to bugs.  Big time investment. You have to write the tests and maintain them.  Additional Complexity. So is it worth it?

JUnit  JUnit in version 4.x (what we are using) is a test framework which uses annotations to identify methods that specify a test.

JUnit Annotations 1/2 public void method() annotation identifies a method as a test = Exception.class)Fails if the method does not throw the named if the method takes longer than 100 public void method() This method is executed before each test. It is used to prepare the test environment (e.g., read input data, initialize the public void method() This method is executed after each test. It is used to cleanup the test environment (e.g., delete temporary data, restore defaults). It can also save memory by cleaning up expensive memory structures.

@BeforeClass public void method() This method is executed once, before the start of all tests. It is used to perform time intensive activities, for example, to connect to a database. Methods marked with this annotation need to be defined as static to work with public void method() This method is executed once, after all tests have been finished. It is used to perform clean-up activities, for example, to disconnect from a database. Methods annotated with this annotation need to be defined as static to work with the test method. This is useful when the underlying code has been changed and the test case has not yet been adapted. Or if the execution time of this test is too long to be included. JUnit Annotations 2/2

Assertions 1/2 StatementDescription fail(String)Let the method fail. Might be used to check that a certain part of the code is not reached or to have a failing test before the test code is implemented. The String parameter is optional. assertTrue([message], boolean condition) Checks that the boolean condition is true. assertFalse([message], boolean condition) Checks that the boolean condition is false. assertEquals([String message], expected, actual) Tests that two values are the same. Note: for arrays the reference is checked not the content of the arrays. assertEquals([String message], expected, actual, tolerance) Test that float or double values match. The tolerance is the number of decimals which must be the same. assertNull([message], object)Checks that the object is null.

Assertions 2/2 assertNotNull([message], object)Checks that the object is not null. assertSame([String], expected, actual)Checks that both variables refer to the same object. assertNotSame([String], expected, actual) Checks that both variables refer to different objects.

Multiply Demo Create a Java Class:

Create new Package called tests:  New>Package  Name new package tests  Right click new package tests>Build Path>Use as source folder

Create a JUnit test  Right click project  New>JUnit Test Case

Wizard allows you to auto-create method stubs:

Prompts to add Junit 4 library jar to build path:

Resulting Class:

testExceptionIsThrown & testMultiply

Run your test in Eclipse:  Right click test class>Run As>JUnit Test

Fix the error:

Passed!