Slide 1 Unit Testing. Slide 2 Unit Testing Options l Use N-Unit In a microsoft environment.NET… you can use their supplied N-Unit testing to test your.

Slides:



Advertisements
Similar presentations
JAVA Revision Lecture Electronic Voting System Marina De Vos.
Advertisements

Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
UML Package Diagrams. package_name presentation view controller model.
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Inheritance Writing and using Classes effectively.
2.4 Creating and Using Objects. Writing the code for classes of your own will come later. At this time it is possible to understand and correctly write.
CIT 590 Intro to Programming Java lecture 3. Hashmaps The equivalent of python dictionaries. With both ArrayLists and Hashmaps, the syntax only allows.
Chapter 9 – Inheritance Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
AP Computer Science.  Not necessary but good programming practice in Java  When you override a super class method notation.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
Refactoring Encapsulation and Unit Testing Lesson Two: Encapsulation and Unit Testing.
Inheritance using Java
1 Exercise /* A lockbox can be open or closed. If closed, only a valid password will open the box. Once the box is open, the contents can be retrieved.
1 Java Methods & Classes – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Object-oriented programming: C++ class A { private: …… // can be accessd by A protected: …… // can be accessed by A and // its derived classes public:
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Software Engineering 1 Object-oriented Analysis and Design Chap 21 Test-Driven Development and Refactoring.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
ECE122 Feb. 22, Any question on Vehicle sample code?
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
Java Class Structure. Class Structure package declaration import statements class declaration class (static) variable declarations* instance variable.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
CIT 590 Intro to Programming Lecture 13. Some Eclipse shortcuts CTRL + SHIFT + F – format file (proper indentation etc). Please do this before you submit.
Inherited Classes in Java CSCI 392 Ch 6 in O’Reilly Adapted from Dannelly.
Introduction To Greenfoot
Inheritance and Polymorphism. Superclass and Subclass Inheritance defines a relationship between objects that share characteristics. It is a mechanism.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Last Revision. Question1 Novice Java programmers often write code similar to, class C { public int x;... }... C[] a = new C[10]; for(int i = 0; i < a.length;
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Review for Test2. Scope 8 problems, 60 points. 1 Bonus problem (5 points) Coverage: – Test 1 coverage – Exception Handling, Switch Statement – Array of.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
User-Written Functions
Process API COMP 755.
Inheritance Notes: Using Object Oriented Design
Class Structure 15-Jun-18.
Java Unit 11: Inheritance I
Types of Programming Languages
UML Class Diagram: class Rectangle
CS/ENGRD 2110 Spring 2018 Lecture 5: Local vars; Inside-out rule; constructors
CS/ENGRD 2110 Spring 2017 Lecture 5: Local vars; Inside-out rule; constructors
CSC 113 Tutorial QUIZ I.
An Introduction to Java – Part II
CS/ENGRD 2110 Fall 2017 Lecture 5: Local vars; Inside-out rule; constructors
Inherited Classes in Java
Subroutines – parameter passing
Assignment 7 User Defined Classes Part 2
Java – Inheritance.
Recitation 7 October 7, 2011.
CS/ENGRD 2110 Fall 2018 Lecture 5: Local vars; Inside-out rule; constructors
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Inheritance CT1513.
Which best describes the relationship between classes and objects?
Yan Shi CS/SE 2630 Lecture Notes
Java Programming with BlueJ Objectives
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Method Overriding and method Overloading
Agenda Inheritance Polymorphism Type compatibility Homework.
Presentation transcript:

Slide 1 Unit Testing

Slide 2 Unit Testing Options l Use N-Unit In a microsoft environment.NET… you can use their supplied N-Unit testing to test your classes l Using J-Unit A free download and integratable with most IDE’s is J-Unit which you can use with Java for unit testing. There are some other unit testing programs for C++, Smalltalk, Eiffel, Ada, etc… They do cost. l Writing your own Unit Testing

Slide 3 Unit Testing Options l Write your own unit testing program. l This allows you to understand unit testing better.

Slide 4 Creating a Unit Test Class Step 1 Create a Unit Test Class Given the class you wish to test YourClassName. Build a class called YourClassNameUnitTest that is a sub-class of YourClassName Unit Test class Your class

Slide 5 Creating a Unit Test Class HOW Step 1 – Create Unit Test Class -- HOW Simply copy your class into another class called YourClassNameUnitTest Make it a a sub-class of YourClassName In the constructor (s) remove the code and call the super-class constructor method In the other methods – rewrite them in the form shown in step 2 Unit Test class Your class

Slide 6 Rewriting Methods Step 2 – Rewriting Methods For all methods that are void--- simply call the super method OR eliminate them if they are not needed for other methods. These void methods should not be changing any class variables but simply doing things that do not change the state of the object. For all methods that return a value. Set up test(s) to assure the correct value is returned.

Slide 7 Your class Method addit (int a, int b):int return a + b; Unit Test class Method addit (int a, int b):int int a = 4; int b = 5; int answer = super (a,b); if answer <> 9 print Error in addit; print expected, “9”; print received, answer; else print OK; Rewriting Methods Example

Slide 8 Creating a Unit Test Executable Step 3 – Create a Unit Test Executable Class Your class Unit test class Unit test EXEC class

Slide 9 Creating a Unit Test Executable Step 3 – Create a Unit Test Executable – How Decide what methods you wish to test. Remember– you will use this for the entire duration of this class …it may change over the years but this test can be run to make sure that changes to this c;ass or other classes in the system do not adversely impact this class….. It helps to keep down the ripple effect of changes

Slide 10 Creating a Unit Test Executable Step 3 – Create a Unit Test Executable – How In the main executable routine Make an instance of the Unit Test Class Call each method in the Unit Test Class that you wish to test Remember, each unit test method may execute many different tests with different parameters.