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.

Slides:



Advertisements
Similar presentations
Unit Testing Australian Development Centre Brisbane, Australia.
Advertisements

Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
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.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
JUnit intro Kalvis Apsitis. What are “Programmer Tests”? Programmer Testing is the testing performed by a developer with the goal of verifying the correct.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Approach of Unit testing with the help of JUnit Satish Mishra
The Simplest Automated Unit Test Framework That Could Possibly Work Chuck Allison.
JUnit. What is unit testing? A unit is the smallest testable part of an application. A unit test automatically verifies the correctness of the unit. There.
JUnit, Revisited 17-Apr-17.
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.
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.
Unit testing C# classes “If it isn’t tested it doesn’t work” Unit testing C# classes1.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
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.
Technion – Institute of Technology Author: Gal Lalouche ©
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:
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMMING PRACTICES Unit Testing.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Testing in Extreme Programming
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
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.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
CSC 216/001 Lecture 4. Unit Testing  Why is it called “unit” testing?  When should tests be written?  Before the code for a class is written.  After.
Test automation / JUnit Building automatically repeatable test suites.
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.
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.
Week81 APCS-AB: Java Unit Testing Information today from “Unit Testing in BlueJ” October 28, 2005.
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
JUnit Don Braffitt Updated: 10-Jun-2011.
Testing code COMP204. How to? “manual” –Tedious, error-prone, not repeatable “automated” by writing code: –Assertions –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.
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,
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?
Unit Testing in Eclipse Presented by David Eisler 08/09/2014.
Testing Technion – Institute of Technology Author: Gal Lalouche © 1 Author: Gal Lalouche - Technion 2016 ©
CSE 143 Lecture 14: testing.
Getting Started with JUnit Getting Started with JUnit The benefits and ease of writing and running JUnit test cases and test suites. The benefits and ease.
Unit Testing.
Software Construction Lab 10 Unit Testing with JUnit
Don Braffitt Updated: 26-Mar-2013
Unit Testing with JUnit
JUnit Automated Software Testing Framework
Introduction to JUnit CS 4501 / 6501 Software Testing
Unit testing Java programs Using JUnit
More JUnit CS 4501 / 6501 Software Testing
Computer Science 209 Testing With JUnit.
Unit testing C# classes
JUnit Automated Software Testing Framework
Test-driven development (TDD)
Introduction to JUnit CS 4501 / 6501 Software Testing
More JUnit CS 4501 / 6501 Software Testing
Introduction to JUnit IT323 – Software Engineering II
Test Driven Development
Section 3 Graphs & Testing
CS 240 – Advanced Programming Concepts
CSC 143 Java More on Exceptions.
JUnit Reading: various web pages
Joel Adams and Jeremy Frens Calvin College
Presentation transcript:

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 aren't broken, don’t fix it” Refactoring, XP Spartanization

What is unit testing? Unit Testing – test a single element of the system. Unit – Class There are other kinds of tests: Functional Testing Stress testing Benchmark testing

Wish list: A testing framework 1. Test expressions: Means for comparing an actual result with an expected result 2. Clear indication of success/failure 3. Clear indication of failed tests 4. Split a long test method into several smaller methods 5. Continue with other tests even if a test fails 6. Continue with other tests even if a test throws an exception 7. No duplication of initialization code of tested objects 8. Side effects should not influence other tests 9. No need to maintain a list of tests

JUnit JUnit is a unit testing framework for Java A test case is a set of conditions to determine whether an application meets specifications. A test suite is a collection of test cases, test suites, or both. A fixture is a set of objects to be tested

JUnit: Benefits Writing a test is as simple as writing a method that exercises the code to be tested and defining the expected result. JUnit gives flexibility in grouping tests and convenient ways to capture and/or summarize test failures. The Assert class has a bunch of static convenience methods for writing test expressions. initialize the fixture state clean-up after a test

JUnit 4

JUnit 4.0 To use assertion need to import org.junit.Assert.* No need to extend from junit.framework.TestCase No need to prefix test method with ‘test’ Test method is method – runs before every method – runs after every – runs once before first test method in its class for one-time set – runs once after the last method in its class for one-time tear down.

JUnit Annotations Checking for annotation can take a parameter, which declares the type of Exception that should be = Exception.class) public void nullPointerParameter() {… The test fails if no exception is thrown. Checking annotation can take a parameter, which declares period in = 10) public void nullPointerParameter() {… The test fails if it takes more than 10 milliseconds. Test annotation mean that test was ignored and not run.

JUnit: Running Textual runner: Called explicitly by user org.junit.runner.JUnitCore.runClasses (TestClass1.class,...); IDE Support To run several TestClass1.class, TestClass2.class, … }) public class AllCalculatorTests { }

JUnit: Source Code Organization Option 1: Test class in same folder as subject A single hierarchy of folders Locality Use a special naming scheme E.g.: SubjectClass_Test Option 2: Keep tests in the mirrored directory structure of source location A duplicated hierarchy of folders Easy to find all tests Easy to separate source code from its tests

JUnit: Black Box vs. White Box Black Box: Write tests against the interface of the subject No need to change tests when implementation is changed. Exponential explosion of the testing space Practically non-feasible White Box: Rely on implementation knowledge when writing tests If implementation is changed need to remember to examine the test Practical: dramatically slices the testing space

Practices: Test Class A test class must have a no-arguments constructor and not the constructor In a suite, shorter tests should be placed first Avoid side effects Testing code should be simpler than subject code

Practices: General Testing is meant to improve the quality of the code  Don’t change a private method into a public one so you can test it Keeping old test running is just as important as making new ones run Run tests as often as possible  The earlier you detect the bug the sooner you solve it When you work on a bug, write a test case first => Your work is done when the test case succeeds When you change the subject class, add tests