MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
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.
Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
J-Unit Framework.
Unit Testing. Topics Motivation JUnit framework Basic JUnit tests – static methods Ensure exceptions – instance methods.
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 Introduction and Advanced Features. Topics Covered  Junit Introduction  Fixtures  Test Suites  Currency Example.
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.
1 Advanced Material The following slides contain advanced material and are optional.
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 & 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
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.
A Safety-Critical Java Technology Compatibility Kit Hans Søndergaard Stephan Korsholm VIA University College, Horsens, Denmark & Anders P. Ravn Aalborg.
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.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
COP 3330 Notes 1/12. Today's topics Downloading Java and Eclipse Hello World Basic control structures Basic I/O Strings.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
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.
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
SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
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.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
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 –
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
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.
Unit Testing in Eclipse Presented by David Eisler 08/09/2014.
Today protected access modifier Using the debugger in Eclipse JUnit testing TDD Winter 2016CMPE212 - Prof. McLeod1.
Test automation / JUnit Building automatically repeatable test suites.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Unit Testing.
Software Construction Lab 10 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
More JUnit CS 4501 / 6501 Software Testing
Junit with.
Test-driven development (TDD)
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to JUnit IT323 – Software Engineering II
Test Driven Development
Testing Acknowledgement: Original slides by Jory Denny.
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
Test Driven Development
JUnit Reading: various web pages
TCSS 360, Spring 2005 Lecture Notes
Junit Tests.
JUnit Tutorial Hong Qing Yu Nov 2005.
Presentation transcript:

MAHDI OMAR JUNIT TUTORIAL

CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature

JUNIT A unit testing framework for the Java Programming Language Used for writing & running tests Versions: Junit3.*, Junit4.*

TERMINOLOGIES Test Case Part of code which ensures that the another part of code (method) works as expected Characterized by a known input (precondition ) and by an expected output (postcondition) Positive test case: verifies a correct functionality Negative test case: verifies that a function will fail or throw an exception Test Suite Contains test cases and run them together Can contain other test suites

INSTALLATION OF JUNIT Eclipse: JUnit integrated into Eclipse Downloading the JUnit library Download JUnit4.x.jar from http: //junit.org/ Add this library to your Java project and add it to the classpath Use the following command lines: To compile: javac “class path” To execute: java org.junit.runner.JUnitCore “test class name”

ECLIPSE SUPPORT FOR JUNIT Creating JUnit tests Manually JUnit test Case creation wizard Running JUnit tests Select Run as → JUnit Test

CREATING JUNIT TESTS

JUNIT EXAMPLE Rational numbers program Create a simple test case Use assertions Equals() method

ASSERT STATEMENTS 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. 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.

JUNIT 4.X ANNOTATIONS public void method() annotation identifies a method as a test (expected = 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 can 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 public static 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 annotated with this annotation need to be defined as static to work with public static 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.

CREATING & RUNNING TEST SUITES Options of running multiple test suites: TestRunner Result TestSuite

QUESTIONS? You can download today’s slides and materials from the link below THANK YOU!