Structured Testing in VDM



Similar documents
Introduction to unit testing with Java, Eclipse and Subversion

VDM vs. Programming Language Extensions or their Integration

Facilitating Consistency Check between Specification and Implementation with MapReduce Framework

Approach of Unit testing with the help of JUnit

Test Driven Development

Using JUnit in SAP NetWeaver Developer Studio

+ Introduction to JUnit. IT323 Software Engineering II By: Mashael Al-Duwais

NEER ENGI ENHANCING FORMAL MODEL- LING TOOL SUPPORT WITH INCREASED AUTOMATION. Electrical and Computer Engineering Technical Report ECE-TR-4

Formal Methods for Software Engineering

VDM++ as a Basis of Scalable Agile Formal Software Development

Author: Sascha Wolski Sebastian Hennebrueder Tutorials for Struts, EJB, xdoclet and eclipse.

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

Case studies: Outline. Requirement Engineering. Case Study: Automated Banking System. UML and Case Studies ITNP090 - Object Oriented Software Design

Section IV.1: Recursive Algorithms and Recursion Trees

16. Recursion. COMP 110 Prasun Dewan 1. Developing a Recursive Solution

Unit Testing and JUnit

Lecture Notes on Binary Search Trees

Regression Verification: Status Report

Unified Static and Runtime Verification of Object-Oriented Software

Going Interactive: Combining Ad-Hoc and Regression Testing

Programming by Contract. Programming by Contract: Motivation. Programming by Contract: Preconditions and Postconditions

E-Commerce VDM and Camila revitalization

Systematically Refactoring Inheritance to Delegation in JAVA

CS 451 Software Engineering Winter 2009

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

Design by Contract beyond class modelling

Table of Contents. LESSON: The JUnit Test Tool...1. Subjects...2. Testing What JUnit Provides...4. JUnit Concepts...5

Unit-testing with JML

CMSC 132: Object-Oriented Programming II. Design Patterns I. Department of Computer Science University of Maryland, College Park

Overview. What is software testing? What is unit testing? Why/when to test? What makes a good test? What to test?

10CS35: Data Structures Using C

Core Maths C1. Revision Notes

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Binary Heap Algorithms

5.1 Radical Notation and Rational Exponents

Math 115 Spring 2011 Written Homework 5 Solutions

Java Interview Questions and Answers

Solving Rational Equations

Unit testing with JUnit and CPPUnit. Krzysztof Pietroszek

BCS HIGHER EDUCATION QUALIFICATIONS Level 6 Professional Graduate Diploma in IT. March 2013 EXAMINERS REPORT. Software Engineering 2

NEER ENGI EVALUATION OF DEVELOPMENT PROCESS AND METHODOLOGY FOR CO-MODELS. Electrical and Computer Engineering Technical Report ECE-TR-12

Analysis of Binary Search algorithm and Selection Sort algorithm

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

A Catalogue of the Steiner Triple Systems of Order 19

Automatic Test Data Synthesis using UML Sequence Diagrams

Outline. 1 Denitions. 2 Principles. 4 Implementation and Evaluation. 5 Debugging. 6 References

Modeling Concurrent Systems with Shared Resources

webmunit for WebMethods Integration Server

Factoring Trinomials of the Form x 2 bx c

1.4 Compound Inequalities

Lecture 11: Tail Recursion; Continuations

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

APPENDIX A: MOCKITO UNIT TESTING TUTORIAL

>

A Link Layer Discovery Protocol Fuzzer

CIA Lab Assignment: Web Servers

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

TESTING WITH JUNIT. Lab 3 : Testing

Answer: The relationship cannot be determined.

Verification of Imperative Programs in Theorema

Question 1. [7 points] Consider the following scenario and assume host H s routing table is the one given below:

An Automated Testing Tool Using UI Structure

ARE YOU A RADICAL OR JUST A SQUARE ROOT? EXAMPLES

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Calculate Highest Common Factors(HCFs) & Least Common Multiples(LCMs) NA1

Introducing the Dezyne Modelling Language

Supplemental Worksheet Problems To Accompany: The Pre-Algebra Tutor: Volume 1 Section 1 Real Numbers

Performance Improvement In Java Application

General Problem Solving Model. Software Development Methodology. Chapter 2A

Roman Numerals Case Study 1996 M. J. Clancy and M. C. Linn

Programming and Software Development CTAG Alignments

Lecture Notes on Linear Search

Sample Induction Proofs

PES Institute of Technology-BSC QUESTION BANK

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Unit Testing. and. JUnit

When factoring, we look for greatest common factor of each term and reverse the distributive property and take out the GCF.

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

Tool-Assisted Unit-Test Generation and Selection Based on Operational Abstractions

Experiences with Online Programming Examinations

COMPUTER SCIENCE. Paper 1 (THEORY)

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Chapter 8: Bags and Sets

JUnit Automated Software Testing Framework. Jeff Offutt. SWE 437 George Mason University Thanks in part to Aynur Abdurazik. What is JUnit?

Slides prepared by : Farzana Rahman TESTING WITH JUNIT IN ECLIPSE

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

23. RATIONAL EXPONENTS

Unit Testing JUnit and Clover

Iteration CHAPTER 6. Topic Summary

Transcription:

Structured Testing in VDM Kenneth Lausdahl and Peter Gorm Larsen May 2011 1 Introduction The Vienna Development Method was initially developed with proof of property in mind. However a number of test principles known for traditional software development is also supported by VDM such as unit-, integration- and system-test. Tool support exists for Unit testing and Combinatorial Testing, the latter is a part of the language where regular expressions can be used to bring a system into a specific state and from there generate tests automatically to check for violation of invariants, pre-, and postconditions in the VDM model. The exercise is divided into three assignments: 1. Specify a number of functions to be tested. 2. Create Unit tests for all functions. Include positive and negative tests. 3. Write a trace for the provided Tree model and see if the trace can detect any errors. 2 VDM Unit testing Unit testing is primary used to test small parts of a model such as a single function/- operation or class. VDM-Unit is a port of the well known JUnit for Java, it enabled a structured test through TestCases and TestSuites. The VDM Unit framework is described in more detail in chapter The VDMUnit Framework of [1], The VDM-Unit library provided for this exercise is a newer version than presented in [1], thus naming and the internal class structure is different. 1

2.1 Specify functions to be tested 1. Write a function that can reverse a sequence of integers. 2. Write a recursive power function for integers: x n e.g. 2 10 = 1024. Remember that x 0 = 1 and that x n+1 = x x n 3. Write a function which creates an onion structure. An onion is build of a small onion with a onion around thus creating a layers structure. In VDM we can see that as an empty list as the middle inner onion a list of numbers as the outer layers such that: makeonion[1, 2, 3, 4] =[1, [2, [3, [4, [], 4], 3], 2], 1] 4. Write a function which creates an onion dual structure: makedualonion[1, 2, 3, 4] =[4, [3, [2, [1, [], 1], 2], 3], 4] -- Use language version = vdm10 functions public reverse : seq of int -> seq of int reverselist == is not yet specified; public power : int * int -> int powerx,n == is not yet specified; types public T = nat1 seq of T; functions public makeonion : seq of int -> seq of T makeonionlist== is not yet specified; public makedualonion : seq of int -> seq of T makedualonionlist== is not yet specified; public static add : nat * nat -> nat adda,b == a+b; Listing 1: Signatures for the functions to test. 2.2 Create Unit tests Now develop test for each of the new functions. Produce at least one positive and one negative test of each function. So if we had an add function it could look like: class TestCaseAdd1 is subclass of TestCase protected runtest : ==> 2

runtest== asserttruefunctions add2,3=5; ; end TestCaseAdd1 class TestCaseAdd2 is subclass of TestCase protected runtest : ==> runtest== assertfalsefunctions add5,5=11; end TestCaseAdd2 Listing 2: Example of a TestCase for the add function. The TestCase s can then easily be executed trough a TestSuite as shown in listing 3 Remember to include the IO library. let ts : TestSuite = new TestSuite, result = new TestResult in ts.addtestnew TestCaseAdd1; ts.addtestnew TestCaseAdd2; ts.runresult; IO printlnresult.tostring; Listing 3: Running TestCases through a TestSuite and printing the result. 2.2.1 Simplified test structure From Overture IDE version 1.0.1 it is possible to run Unit tests in a similar way as JUnit, where the VDM interpreter is able to search for test within a TestCase or a sub class here of, and run all of tests found. This is possible by instantiating a TestSuite with a single or a set of classes which are sub classes of TestCase. class TestCaseFunctions protected testadd235 : ==> testadd235== asserttruefunctions add2,3=5; ; 3

protected testadd5511 : ==> testadd5511== assertfalsefunctions add5,5=11; end TestCaseFunctions Listing 4: A single TestCase where all prefixed test will be extracted and executed. let ts : TestSuite = new TestSuitenew TestCaseFunctions, result = new TestResult in ts.runresult; IO printlnresult.tostring; Listing 5: Running all prefixed test in TestCases through a TestSuite and printing the result. 3 Combinatorial Testing in VDM Combinatorial Testing is a good alternative to normal Unit testing for VDM models. Since formally specified VDM models often are accompanied by pre- and postconditions and also invariants the allowed behaviour of the VDM model is restricted. This can be utilised through combinatorial testing since tests can be generated and validated against these invariants, pre- and post-conditions. Combinatorial testing in VDM is build to allow a modeller to get a VDM model into a particular state and then specify a scenario by the use of constructs such as alternatives and repetition which then can be expanded to all possible combinations. This will in most cases generate a large number of tests even for small test traces. Exercise: A Tree VDM model is on purpose provided with at least one error. Specify a trace which uses the different search mechanisms of the tree. Through this identify existing errors. When a trace test fails then try to send it to the interpreter and debug the problem and fix the errors. So your tasks can be summarised as: 1. Extend the UseTree class with a more advanced trace definition. 2. Try out the Combinatorial Testing perspective CT 1. 1 This is a prototype, thus you might discover minor instabilities, but the main features should work correctly. 4

3. Try to run a full test. 4. Try to see of any of the reduced options is enough to detect the problem. Faster executions. 5. Try to send a test case to the interpreter. When doing so this should be similar to running a manually specified Unit test. 6. Fix the errors you might discover. References [1] John Fitzgerald, Peter Gorm Larsen, Paul Mukherjee, Nico Plat, and Marcel Verhoef. Validated Designs for Object oriented Systems. Springer, New York, 2005. 5