Separation of Concerns Tao Xie Peking University, China North Carolina State University, USA In collaboration with Nikolai Tillmann, Peli de Halleux, Wolfram.

Slides:



Advertisements
Similar presentations
Leonardo de Moura Microsoft Research. Z3 is a new solver developed at Microsoft Research. Development/Research driven by internal customers. Free for.
Advertisements

Tutorial Pex4Fun: Teaching and Learning Computer Science via Social Gaming Nikolai Tillmann, Jonathan de Halleux, Judith Bishop, Michal.
Testing Object Oriented Programs CSE 111 4/28/20151.
Integration Testing When testing a module in isolation –Called modules need to be replaced –Tested module needs to be called A D ′ E ′ main driver module.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
Pexxxx White Box Test Generation for
Program Exploration with Pex Nikolai Tillmann, Peli de Halleux Pex
Peli de Halleux, Nikolai Tillmann Research in Software Engineering Microsoft Research, Redmond, USA.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Deep Dive into Pex How Pex works, implications for design of Code Hunt puzzles Nikolai Tillmann Principal Software Engineering Manager Microsoft, Redmond,
Programming Languages and Paradigms Object-Oriented Programming.
Eclipse – making OOP Easy
Tao Xie North Carolina State University Supported by CACC/NSA Related projects supported in part by ARO, NSF, SOSI.
Automated Testing of System Software (Virtual Machine Monitors) Tao Xie Department of Computer Science North Carolina State University
Tao Xie (North Carolina State University) Nikolai Tillmann, Jonathan de Halleux, Wolfram Schulte (Microsoft Research, Redmond WA, USA)
Automated Developer Testing: Achievements and Challenges Tao Xie North Carolina State University contact:
Eric Vogel Software Developer A.J. Boggs & Company.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Designing For Testability. Incorporate design features that facilitate testing Include features to: –Support test automation at all levels (unit, integration,
Tao Xie Automated Software Engineering Group Department of Computer Science North Carolina State University
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
Testing Especially Unit Testing. V-model Wikipedia:
Teaching and Learning Programming and Software Engineering via Interactive Gaming Tao Xie University of Illinois at Urbana-Champaign In collaboration with.
Abstract Factory Design Pattern making abstract things.
Modularizing Web Services Management with AOP María Agustina Cibrán, Bart Verheecke { Maria.Cibran, System and Software Engineering.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
A Novel Approach to Unit Test: The Aspect-Oriented Way Guoqing Xu and Zongyuan Yang Software Engineering Lab (SEL) East China Normal University
DEV411 Testing Un-Testable Code with Visual Studio 2012 Fakes Peter Provost Sr. Program Manager Lead Microsoft Corporation DEV411.
Tao Xie North Carolina State University Nikolai Tillmann, Peli de Halleux, Wolfram Schulte Microsoft Research.
Code Contracts Parameterized Unit Tests Tao Xie. Example Unit Test Case = ? Outputs Expected Outputs Program + Test inputs Test Oracles 2 void addTest()
Parameterized Unit Tests By Nikolai Tillmann and Wolfram Schulte Proc. of ESEC/FSE 2005 Presented by Yunho Kim Provable Software Lab, KAIST TexPoint fonts.
A Distributed Aspect-Oriented System for J2EE Applications Muga Nishizawa and Shigeru Chiba (Tokyo Institute of Technology, Japan) Background - As benefits.
Refactoring1 Improving the structure of existing code.
CS527 Topics in Software Engineering (Software Testing and Analysis) Darko Marinov September 22, 2011.
Tao Xie (North Carolina State University) Peli de Halleux, Nikolai Tillmann, Wolfram Schulte (Microsoft Research)
Towards a Practical Approach to Testing Pointcut Descriptors With JQuati 1 LA-WASP 2009.
Mining Gigabytes of Dynamic Traces for Test Generation Suresh Thummalapenta North Carolina State University Peli de Halleux and Nikolai Tillmann Microsoft.
Nikolai Tillmann, Jonathan de Halleux Tao Xie Microsoft Research Univ. Illinois at Urbana-Champaign.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Xusheng Xiao North Carolina State University CSC 720 Project Presentation 1.
Cooperative Developer Testing: Tao Xie North Carolina State University In collaboration with Xusheng ASE and Nikolai Tillmann, Peli de
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
Tao Xie (North Carolina State University) Nikolai Tillmann, Peli de Halleux, Wolfram Schulte (Microsoft Research)
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Parameterized Unit Testing in the Open Source Wild Wing Lam (U. Illinois) In collaboration with Siwakorn Srisakaokul, Blake Bassett, Peyman Mahdian and.
1 Exposing Behavioral Differences in Cross-Language API Mapping Relations Hao Zhong Suresh Thummalapenta Tao Xie Institute of Software, CAS, China IBM.
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Refactoring1 Improving the structure of existing code.
Mocking Unit Testing Methods with External Dependencies SoftUni Team Technical Trainers Software University
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
Symbolic Execution in Software Engineering By Xusheng Xiao Xi Ge Dayoung Lee Towards Partial fulfillment for Course 707.
1 CSC 533: Programming Languages Spring 2014 Subprogram implementation  subprograms (procedures/functions/subroutines)  subprogram linkage  parameter.
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
Testing Tutorial 7.
John D. McGregor Session 9 Testing Vocabulary
Dynamic Symbolic Execution
Inheritance and Polymorphism
Chapter 8 – Software Testing
John D. McGregor Session 9 Testing Vocabulary
Code Contracts and Pex Peli de Halleux, Nikolai Tillmann
White-Box Testing Using Pex
John D. McGregor Session 9 Testing Vocabulary
Java Programming Language
DEV411 Testing Un-Testable Code with Visual Studio 2012 Fakes
Designing For Testability
Aspect Oriented Software Design
Presentation transcript:

Separation of Concerns Tao Xie Peking University, China North Carolina State University, USA In collaboration with Nikolai Tillmann, Peli de Halleux, Wolfram Research and ASE

 Separation of Concerns (SoC)  Aspect-Oriented Software Development (AOSD)  “Killer Apps” for SoC/AOSD?  Logging, Security Checking, …  Any Other Application Scenarios in Practice?  Tool Support for Software Testing?

= ? Outputs Expected Outputs Program + Test inputs Test Oracles

= ? Outputs Expected Outputs Program + Test inputs Test Oracles  Test Generation  Generating high-quality test inputs (e.g., achieving high code coverage)

= ? Outputs Expected Outputs Program + Test inputs Test Oracles  Test Generation  Generating high-quality test inputs (e.g., achieving high code coverage)  Test Oracles  Specifying high-quality test oracles (e.g., guarding against various faults)

var list = new ArrayList(); list.Add(item); var list = new ArrayList(); list.Add(item); Assert.AreEqual(1, list.Count); } Assert.AreEqual(1, list.Count); }  Three essential ingredients:  Data  Method Sequence  Assertions void TestAdd() { int item = 3; void TestAdd() { int item = 3;

 Parameterized Unit Testing  Separate Test Generation and Behavior Specification  Test Generalization  Localize Crosscutting Concerns of Behavior Under Test  Object Creation with Factory Method  Localize Crosscutting Concerns of Object Creation  Environment Isolation with Moles  Localize Crosscutting Concerns of Environment Dependency

void TestAdd(ArrayList list, int item) { Assume.IsTrue(list != null); var count = list.Count; list.Add(item); Assert.AreEqual(count + 1, list.Count); } void TestAdd(ArrayList list, int item) { Assume.IsTrue(list != null); var count = list.Count; list.Add(item); Assert.AreEqual(count + 1, list.Count); }  Parameterized Unit Test = Unit Test with Parameters  Separation of concerns  Data is generated by a tool  Developer can focus on functional specification [Tillmann&Schulte ESEC/FSE 05]

Code to generate inputs for: Constraints to solve a!=null a!=null && a.Length>0 a!=null && a.Length>0 && a[0]== void TestMe(int[] a) { if (a == null) return; if (a.Length > 0) if (a[0] == ) throw new Exception("bug"); } void TestMe(int[] a) { if (a == null) return; if (a.Length > 0) if (a[0] == ) throw new Exception("bug"); } Observed constraints a==null a!=null && !(a.Length>0) a!=null && a.Length>0 && a[0]!= a!=null && a.Length>0 && a[0]== Data null {} {0} {123…} a==null a.Length>0 a[0]==123… T T F T F F Execute&Monitor Solve Choose next path Done: There is no path left. Negated condition

Download counts (20 months) (Feb Oct ) Academic: 17,366 Devlabs: 13,022 Total: 30,388 Dynamic Symbolic Execution [Tillmann&de Halleux TAP 08]

669,584 clicked 'Ask Pex!‘ since 2010 summer Try it at

Parameterized Unit Tests (PUTs) commonly supported by various test frameworks .NET: Supported by.NET test frameworks    …  Java: Supported by JUnit 4.X  Generating test inputs for PUTs supported by tools .NET: Supported by Microsoft Research Pex   Java: Supported by Agitar AgitarOne 

 Benefits over CUTs  Help describe behaviours for all test arguments  Address two main issues with CUTs  Missing test data (that would exercise important behavior) ▪ Low fault-detection capability  Redundant test data and scenarios (that exercises the same behaviour) ▪ Redundant unit tests

 Parameterized Unit Testing  Separate Test Generation and Behavior Specification  Test Generalization  Localize Crosscutting Concerns of Behavior Under Test  Object Creation with Factory Method  Localize Crosscutting Concerns of Object Creation  Environment Isolation with Moles  Localize Crosscutting Concerns of Environment Dependency

public void CUT1() { int elem = 1; IntStack stk = new IntStack(); stk.Push(elem); Assert.AreEqual(1, stk.Count()); } Three CUTs public void CUT2() { int elem = 30; IntStack stk = new IntStack(); stk.Push(elem); Assert.AreEqual(1, stk.Count()); } public void CUT3() { int elem1 = 1, elem2 = 30; IntStack stk = new IntStack(); stk.Push(elem1); stk.Push(elem2); Assert.AreEqual(2, stk.Count()); }  CUT1 and CUT2 exercise push with different test data  CUT3 exercises push when stack is not empty Two main issues with CUTs:  Fault-detection capability: undetected defect where things go wrong when passing a negative value to push  Redundant tests: CUT2 is redundant with respect to CUT1

16 public void CUT1() { int elem = 1; IntStack stk = new IntStack(); stk.Push(elem); Assert.AreEqual(1, stk.Count()); } Three CUTs public void CUT2() { int elem = 30; IntStack stk = new IntStack(); stk.Push(elem); Assert.AreEqual(1, stk.Count()); } public void CUT3() { int elem1 = 1, elem2 = 30; IntStack stk = new IntStack(); stk.Push(elem1); stk.Push(elem2); Assert.AreEqual(2, stk.Count()); }  No need to describe test data Generated automatically  Single PUT replaces multiple CUTs With reduced size of test code public void PUT(int[] elem) { Assume.IsTrue(elem != null); IntStack stk = new IntStack(); for(int i in elem) stk.push(elem); Assert.AreEqual(elem.Length, stk.count()); } An equivalent PUT [ Thummalapenta et al. FASE 11]

 Refactoring clone instances (crosscutting concerns) to a single copy (aspects)  Need pointcuts to specify join points, i.e., which original code locations to weave the aspects  Test generalization is different  Original code locations (old CUTs) are thrown away  PUTs + Pex generate new CUTs  No need of join points or pointcuts

 Parameterized Unit Testing  Separate Test Generation and Behavior Specification  Test Generalization  Localize Crosscutting Concerns of Behavior Under Test  Object Creation with Factory Method  Localize Crosscutting Concerns of Object Creation  Environment Isolation with Moles  Localize Crosscutting Concerns of Environment Dependency

void TestAdd(ArrayList list, int item) { Assume.IsTrue(list != null); var count = list.Count; list.Add(item); Assert.AreEqual(count + 1, list.Count); } void TestAdd(ArrayList list, int item) { Assume.IsTrue(list != null); var count = list.Count; list.Add(item); Assert.AreEqual(count + 1, list.Count); }

 Pex uses public methods to configure non- public object fields  Heuristics built-in to deal with common types  User can help if needed [PexFactoryMethod(typeof(ArrayList))] public static ArrayList Create(int capacity, object[] items) { var list = new ArrayList(capacity); foreach (var item in items) list.Add(item); return list; } [PexFactoryMethod(typeof(ArrayList))] public static ArrayList Create(int capacity, object[] items) { var list = new ArrayList(capacity); foreach (var item in items) list.Add(item); return list; }

[PexFactoryMethod(typeof(ArrayList))] public static ArrayList Create(int capacity, object[] items) { var list = new ArrayList(capacity); foreach (var item in items) list.Add(item); return list; } [PexFactoryMethod(typeof(ArrayList))] public static ArrayList Create(int capacity, object[] items) { var list = new ArrayList(capacity); foreach (var item in items) list.Add(item); return list; } void TestAdd(ArrayList list, int item) { Assume.IsTrue(list != null); var count = list.Count; list.Add(item); Assert.AreEqual(count + 1, list.Count); } void TestAdd(ArrayList list, int item) { Assume.IsTrue(list != null); var count = list.Count; list.Add(item); Assert.AreEqual(count + 1, list.Count); }

 Parameterized Unit Testing  Separate Test Generation and Behavior Specification  Test Generalization  Localize Crosscutting Concerns of Behavior Under Test  Object Creation with Factory Method  Localize Crosscutting Concerns of Object Creation  Environment Isolation with Moles  Localize Crosscutting Concerns of Environment Dependency

 Components depend on other components  Hidden Integration Tests void FileExistsTest() { File.Write(“foo.txt”, “”); var result = IsFileEmpty(“foo.txt”) Assert.IsTrue(result); } void FileExistsTest() { File.Write(“foo.txt”, “”); var result = IsFileEmpty(“foo.txt”) Assert.IsTrue(result); } bool IsFileEmpty(string file) { var content = File.ReadAllText(file); return content.Length == 0; } bool IsFileEmpty(string file) { var content = File.ReadAllText(file); return content.Length == 0; } File.ReadAllText(file); File.Write(“foo.txt”, “”);

 Slow, complicated setup, non-deterministic tests  Solution: Replace by Simpler Environment (“mocking”)  Testable Design: Abstraction layer + Dependency Injection + Mocks for testing  Simply use virtual methods (i.e., overridenable)  Hard-coded Design: No abstraction layer, static methods, sealed types (i.e., not inheritable).

 Replace any.NET method with a Delegate  similar to a C++ function pointer  Method can be overridden? Use Stubs  Interfaces  Abstract classes  Virtual methods in non-sealed types  Method cannot be overridden? Use Moles

 Existing external components cannot be re- factored  SharePoint, ASP.NET, …  Need mechanism to stub non-virtual methods  Static methods, methods in sealed types, constructors

 Method redirected to user delegate, i.e. moled  Requires code instrumentation bool result = IsFileEmpty(“foo.txt”); Assert.IsTrue(result); bool result = IsFileEmpty(“foo.txt”); Assert.IsTrue(result); MFile.ReadAllTextString = file => “”; expression lambda : (input parameters) => expression MFile.ReadAllTextString = file => “”; expression lambda : (input parameters) => expression [de Halleux&Tillmann TOOLS 10]

File.ReadAllText(string name) { } File.ReadAllText(string name) { } mscorlib.dll File.ReadAllText(string name) { var d = GetDetour(); if (d != null) return d(); } File.ReadAllText(string name) { var d = GetDetour(); if (d != null) return d(); } push ecx push edx push eax push ecx push edx push eax.NET Runtime Just In Time Compiler.NET Runtime Just In Time Compiler ExtendedReflection

 Automated White box Analysis does not ‘understand’ the environment  Isolate Code using Stubs and Moles if (DateTime.Now == new DateTime(2000,1,1)) throw new Y2KException(); if (DateTime.Now == new DateTime(2000,1,1)) throw new Y2KException(); DateTime.Now ??? public void TestY2k(DateTime dt) { MDateTime.NowGet = () => dt... } public void TestY2k(DateTime dt) { MDateTime.NowGet = () => dt... } MDateTime.NowGet = () => dt DateTime.Now == dt

 Parameterized Unit Testing  Separate Test Generation and Behavior Specification  Test Generalization  Localize Crosscutting Concerns of Behavior Under Test  Object Creation with Factory Method  Localize Crosscutting Concerns of Object Creation  Environment Isolation with Moles  Localize Crosscutting Concerns of Environment Dependency Application Scenarios of Separation of Concerns in Practice

Questions ?