A Novel Approach to Unit Test: The Aspect-Oriented Way Guoqing Xu and Zongyuan Yang Software Engineering Lab (SEL) East China Normal University

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Advertisements

1. Define the concept of assertions. 1 Explain the use of assertions. 2 Create Java program using assertions. 3 Run Java program using assertions. 4 2.
Automated Evaluation of Runtime Object States Against Model-Level States for State-Based Test Execution Frank(Weifeng) Xu, Gannon University Dianxiang.
Korat Automated Testing Based on Java Predicates Chandrasekhar Boyapati, Sarfraz Khurshid, Darko Marinov MIT ISSTA 2002 Rome, Italy.
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
ASTA Aspect Software Testing Assistant Juha Gustafsson, Juha Taina, Jukka Viljamaa University of Helsinki.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
 Both System.out and System.err are streams—a sequence of bytes.  System.out (the standard output stream) displays output  System.err (the standard.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Modularization.
JMLAutoTest and Its Double- phase Testing Way Guoqing Xu Com Sci., East China Normal Univ. Shanghai , PRC FATES 2003, Montreal, Canada, Oct.6th 2003.
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor Formal Methods in Software Engineering1.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
ITEC200 Week02 Program Correctness and Efficiency.
October - December 2013CSC5021: The Problem With Aspects (J P Gibson)1 The Problem With Aspects (AOP) A style of programming that attempts to abstract.
An overview of JML tools and applications Lilian Burdy Gemplus Yoonsik Cheon, Gary Leavens Iowa Univ. David Cok Kodak Michael Ernst MIT Rustan Leino Microsoft.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Exceptions in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chair of Software Engineering Automatic Verification of Computer Programs.
1/23/2003University of Virginia1 Korat: Automated Testing Based on Java Predicates CS751 Presentation by Radu Stoleru C.Boyapaty, S.Khurshid, D.Marinov.
Exceptions. Many problems in code are handled when the code is compiled, but not all Some are impossible to catch before the program is run  Must run.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
CS203 Java Object Oriented Programming Errors and Exception Handling.
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.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
VERIFICATION OF ASPECT ORIENTED MODELS BY DON MARTIN JAYASHREE VENKIPURAM PATHANGI PIYUSH SRIVASTAVA REFERENCES F. Mostefaoui and J. Vachon,” Design level.
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
Modularizing Web Services Management with AOP María Agustina Cibrán, Bart Verheecke { Maria.Cibran, System and Software Engineering.
Using Aspects to Support the Software Process: XP over Eclipse Oren Mishali and Shmuel Katz Technion, Israel Institute of Technology.
Exception Handling in JAVA. Introduction Exception is an abnormal condition that arises when executing a program. In the languages that do not support.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
VERIFICATION OF ASPECT-ORIENTED MODELS Review of Aspect-Oriented Definitions aspect – crosscutting concern that may involve multiple classes pointcut –
JCMP: Linking Architecture with Component Building Guoqing Xu, Zongyuan Yang and Haitao Huang Software Engineering Lab, East China Normal University SACT-01,
Introduction to Software Testing. Types of Software Testing Unit Testing Strategies – Equivalence Class Testing – Boundary Value Testing – Output Testing.
1.  Writing snippets of code that try to use methods (functions) from your program.  Each snippet should test one (and only one) function......by calling.
CSC 395 – Software Engineering Lecture 10: Execution-based Testing –or– We can make it better than it was. Better...faster...agiler.
A Distributed Aspect-Oriented System for J2EE Applications Muga Nishizawa and Shigeru Chiba (Tokyo Institute of Technology, Japan) Background - As benefits.
Today’s Agenda  Quick Review  Continue on JML Formal Methods in Software Engineering1.
AspectWrapper CHALFOUN Pierre et BUIST Éric. Overview Introduction – what and why In a nutshell – main components Our approach – how we did it Demo –
BIO Java 1 Exception Handling Aborting program not always a good idea – can’t lose messages – E-commerce: must ensure correct handling of private.
1 An Aspect-Oriented Implementation Method Sérgio Soares CIn – UFPE Orientador: Paulo Borba.
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
© Mohamed Nuzrath Java Programming :: Chapter 6 :: Prepared & Presented By :: Mohamed Nuzrath [ Major In Programming ] NCC Programme coordinator IT Lecturer.
Weaving a Debugging Aspect into Domain-Specific Language Grammars SAC ’05 PSC Track Santa Fe, New Mexico USA March 17, 2005 Hui Wu, Jeff Gray, Marjan Mernik,
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Alloy-based Lightweight Verification for Aspect-oriented Architecture Naoyasu Ubayashi(Kyushu Institute of Technology) Yuki Sato(Kyushu Institute of Technology)
Click to edit Master text styles JavaMOP Hamid Reza Niroomand A presentation to Dr. Babamir.
JAOUT: Automated Generation of Aspect Oriented Unit Test Guoqing Xu, Z. Yang, H. Huang, Q. Chen, L. Chen and F. Xu Software Engineering Lab (SEL) East.
Facilitating testing and monitoring of number entry systems in medical devices Abigail Cauchi, Christian Colombo, Mark Micallef & Gordon Pace.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
AOSD'04, Lancaster, UK 1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech) Shigeru Chiba (Tokyo Tech) Michiaki Tatsubori.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
R R R A Brief Introduction to Aspect-Oriented Programming.
( = “unknown yet”) Our novel symbolic execution framework: - extends model checking to programs that have complex inputs with unbounded (very large) data.
Whole Test Suite Generation. Abstract Not all bugs lead to program crashes, and not always is there a formal specification to check the correctness of.
Lecture10 Exception Handling Jaeki Song. Introduction Categories of errors –Compilation error The rules of language have not been followed –Runtime error.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 10: Programming Exceptionally.
Random Test Generation of Unit Tests: Randoop Experience
Defensive Programming. Good programming practices that protect you from your own programming mistakes, as well as those of others – Assertions – Parameter.
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
PPL 2004, Gamagori, AICHI1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech, Japan) Shigeru Chiba (Tokyo Tech, Japan)
Introduction to JUnit CS 4501 / 6501 Software Testing
Formally Specified Monitoring of Temporal Properties
Introduction to JUnit IT323 – Software Engineering II
Test Driven Development
Test Driven Development
Test-Driven Development
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

A Novel Approach to Unit Test: The Aspect-Oriented Way Guoqing Xu and Zongyuan Yang Software Engineering Lab (SEL) East China Normal University Oct at ISFST Oct at ISFST

Background Test Oracle problem Test Oracle problem -- how to identify oracles in unit test? -- how to identify oracles in unit test? Automating the test oracle generation Automating the test oracle generation -- Manually writing test codes is a labor-intensive job. -- Manually writing test codes is a labor-intensive job. -- Cheon and Leavens automatically generate JUnit test codes and use JML runtime assertions as test oracle to test the Java programs annotated with JML specifications [CL02]. -- Cheon and Leavens automatically generate JUnit test codes and use JML runtime assertions as test oracle to test the Java programs annotated with JML specifications [CL02]. Automating the test case generation Automating the test case generation -- Korat generates test cases based on java predicts. [BKM02] -- Korat generates test cases based on java predicts. [BKM02] -- JMLAutoTest generates test cases based on JML class invariants specified in the program. [XY03] -- JMLAutoTest generates test cases based on JML class invariants specified in the program. [XY03]

Problems Current test automating process relies on formal assertions and predicts. Current test automating process relies on formal assertions and predicts. Traditional specifications only focus on programs ’ functional behaviors, with little support for specifying their non-functional behaviors, e.g. temporal logic, performance... Traditional specifications only focus on programs ’ functional behaviors, with little support for specifying their non-functional behaviors, e.g. temporal logic, performance... How to find oracles to test non-functional aspects? How to automate this process? How to find oracles to test non-functional aspects? How to automate this process?

Our approach In Aspect-Oriented Programming (AOP), crosscutting properties are monitored to model the program from different aspects, a lot of tasks which have been difficult to be handled in traditional ways are easily done. In Aspect-Oriented Programming (AOP), crosscutting properties are monitored to model the program from different aspects, a lot of tasks which have been difficult to be handled in traditional ways are easily done. Using a crosscutting property of the program as the criterion to check the correctness of the application in the corresponding aspect is well suited to the unit testing problems. Using a crosscutting property of the program as the criterion to check the correctness of the application in the corresponding aspect is well suited to the unit testing problems.

Application-specific Aspect A new notion: application-specific aspects (ASS) A new notion: application-specific aspects (ASS) -- top-level application related aspects. -- top-level application related aspects. -- established at the design level. -- established at the design level. -- may be picked up from low language level aspects. -- may be picked up from low language level aspects. -- all the ASS for the same use share some common features, e.g. testing ASS, tracing ASS all the ASS for the same use share some common features, e.g. testing ASS, tracing ASS may be translated into language level aspects. -- may be translated into language level aspects.

Aspect-Oriented Test Description Language How to describe ASS? How to describe ASS? -- a formal way is needed. -- a formal way is needed. -- can not be too complicated. -- can not be too complicated. Aspect-Oriented Test Description Language(AOTDL) Aspect-Oriented Test Description Language(AOTDL) -- uses the first order predict logic as part of its syntax -- uses the first order predict logic as part of its syntax -- used by the designer at design level -- used by the designer at design level -- can be translated into AspectJ aspects. -- can be translated into AspectJ aspects. Basic units in AOTDL Basic units in AOTDL -- Utility unit -- Utility unit -- MeaninglessCase Advice unit -- MeaninglessCase Advice unit -- Error Advice unit -- Error Advice unit advicetype (arguments): pointcuts: conditions: message advicetype (arguments): pointcuts: conditions: message

AOTDL (cond.) Class Stack{ public void init(){...} public void init(){...} public void push ( Node n){...} public void push ( Node n){...}......} TestingAspect tempLogic{ Utility{ protected boolean isInitialized = false; protected boolean isInitialized = false; //push is reached //push is reached pointcut pushReached(Stack st): pointcut pushReached(Stack st): target(st)&&call(void Stack.push(Integer)); target(st)&&call(void Stack.push(Integer)); //init is reached //init is reached pointcut initReached(Stack st): pointcut initReached(Stack st): target(st)&&call(void Stack.init(void)); target(st)&&call(void Stack.init(void)); // after advice // after advice after(Stack st):initReached (st){ after(Stack st):initReached (st){ isInitialized = true; isInitialized = true; }}

AOTDL (cond.) MeaninglessCase Advice{ /*advices for specifying criteria of meaningless test cases */ /*advices for specifying criteria of meaningless test cases */ before(Stack s) : before(Stack s) : pushReached(s) : pushReached(s) : s.getSize() >=MAX : ” Overflow ” ; s.getSize() >=MAX : ” Overflow ” ; } Error Advice{ /*advices for specifying criteria of test errors */ /*advices for specifying criteria of test errors */ before(Stack s): before(Stack s): pushReached(s): pushReached(s): ! isInitialized : ” Not Initialized ” ; ! isInitialized : ” Not Initialized ” ; }}

AOTDL (cond.) //error advices //error advices before(Stack s) throws TestErrorException: before(Stack s) throws TestErrorException: pushReached(s){ pushReached(s){ if (!isInitialized){ if (!isInitialized){ TestErrorException ex =new TestErrorException ex =new TestErrorException( “ Not Initialized ” ); TestErrorException( “ Not Initialized ” ); ex.setSource( “ TempLogic ” ); ex.setSource( “ TempLogic ” ); throw ex; throw ex; }}

JAOUT: Automated Generation of AO Testing Framework

JAOUT takes Java class M.java as the input, and automatically generate JUnit test framework. JAOUT takes Java class M.java as the input, and automatically generate JUnit test framework. -- Aspect_M_Test.java, the JUnit unit test class. -- Aspect_M_Test.java, the JUnit unit test class. -- Aspect_M_TestCase.java, the test case provider. -- Aspect_M_TestCase.java, the test case provider. -- Aspect_M_TestClient.java, JMLAutoTest test case generation class. -- Aspect_M_TestClient.java, JMLAutoTest test case generation class.

Test Suite Definition For class C and its method M(A1 a1, A2 a2 … An an), the generated test suite is defined as For class C and its method M(A1 a1, A2 a2 … An an), the generated test suite is defined as --- C[ ] receivers --- C[ ] receivers -- A1[ ] vA1;... ; An[ ] vAn; -- A1[ ] vA1;... ; An[ ] vAn; There is a corresponding init_Ai method for each type Ai and a method init_receiver in test case provider to initialize test cases. There is a corresponding init_Ai method for each type Ai and a method init_receiver in test case provider to initialize test cases. Testers use APIs provided by JMLAutoTest to generate test case space in test client, and pass it to the test case provider. Testers use APIs provided by JMLAutoTest to generate test case space in test client, and pass it to the test case provider.

Generated Test Method public void testM(){ for (int i0 = 0; io < receiver.length; i0++){ for (int i1 = 0; i1 < a1.length; i1++){ for (int i1 = 0; i1 < a1.length; i1++){ … try { try { receiver[i0].M(a1[i1], : : :, an[in]); receiver[i0].M(a1[i1], : : :, an[in]); } catch (MeaninglessCaseException e) { } catch (MeaninglessCaseException e) { /*... tell framework test case was meaningless... */ /*... tell framework test case was meaningless... */ continue; continue; } catch (TestErrorException e) { String msg = e.getSource(); String msg = e.getSource(); fail(msg + NEW LINE + e.getMessage()); fail(msg + NEW LINE + e.getMessage()); } catch (java.lang.Throwable e) { } catch (java.lang.Throwable e) { continue; continue; } finally { } finally { setUp(); // restore test cases setUp(); // restore test cases }}}

Test Result...in push...in push false false F Time: 0.06 Time: 0.06 There was 1 failure: There was 1 failure: 1) testPush (sample.Stack_Aspect_TestCase)junit.framework.AssertionFailedError: In Testing Aspect TempLogic: Not Initilized! 1) testPush (sample.Stack_Aspect_TestCase)junit.framework.AssertionFailedError: In Testing Aspect TempLogic: Not Initilized! at ample.Stack_Aspect_Test.testPush at ample.Stack_Aspect_Test.testPush (Stack_Aspect_Test.java:155) (Stack_Aspect_Test.java:155) at sun.reflect.NativeMethodAccessorImpl.invoke0 at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) (DelegatingMethodAccessorImpl.java:25) at sample.Stack_Aspect_Test.run(Stack_Aspect_Test.java:26) at sample.Stack_Aspect_Test.run(Stack_Aspect_Test.java:26) at sample.Stack_Aspect_TestCase.main at sample.Stack_Aspect_TestCase.main (Stack_Aspect_TestCase.java:24) (Stack_Aspect_TestCase.java:24) FAILURES!!! FAILURES!!! Tests run: 3, Failures: 1, Errors: 0, Meaningless:0 Tests run: 3, Failures: 1, Errors: 0, Meaningless:0

Related Work (Spec-based test) TestEra – Automating OO test generation. [MK01] MIT TestEra – Automating OO test generation. [MK01] MIT JMLUnit – Generating test oracles from JML runtime assertions. [CL02] Iowa State Univ. JMLUnit – Generating test oracles from JML runtime assertions. [CL02] Iowa State Univ. Korat – Generating test case based on Java predicts. [BKM02] MIT. Korat – Generating test case based on Java predicts. [BKM02] MIT. JMLAutoTest – Generating test framework from JML runtime assertions and test cases based on class invariants. [XY03] ECNU. JMLAutoTest – Generating test framework from JML runtime assertions and test cases based on class invariants. [XY03] ECNU. Jov -- java automated unit test based on inferred program properties. [XN03] Univ. of Washington. Jov -- java automated unit test based on inferred program properties. [XN03] Univ. of Washington.

Conclusions Traditional formal predicts tend not to deal with non-functional properties of the program. Traditional formal predicts tend not to deal with non-functional properties of the program. AOP is well suited to the unit test problems. AOP is well suited to the unit test problems. Designers use AOTDL to build Application- Specific Testing Aspects. Designers use AOTDL to build Application- Specific Testing Aspects. JAOUT translates Testing Aspects to AspectJ aspects automatically. JAOUT translates Testing Aspects to AspectJ aspects automatically. JAOUT automatically generates JUnit test framework and uses the runtime messages thrown by Testing Aspects as test oracles. JAOUT automatically generates JUnit test framework and uses the runtime messages thrown by Testing Aspects as test oracles.

Thank you … Questions?