• No results found

Integration test in SharePoint

N/A
N/A
Protected

Academic year: 2021

Share "Integration test in SharePoint"

Copied!
37
0
0

Loading.... (view fulltext now)

Full text

(1)

Introduction Unit testing Integration testing

Integration test in SharePoint

Allan Hvam Petersen

Codecamp, SharePoint User Group

(2)

Introduction Unit testing Integration testing

Me

Education

B.Sc. in Computer Science

AP in Computer Science

SharePoint experience

SharePoint Developer at ProActive since 2007

Questions B Just ask

Q: Do you have any practical experiences with the topic?

A: No, testing has been a small spare time project.

(3)

Introduction

Unit testing Integration testing

Agenda

Software testing

Automated functional testing

Agenda

1

Introduction

Agenda

Software testing

Automated functional testing

2

Unit testing

Dependency inversion

Mocking

TypeMock Isolator

3

Integration testing

Considerations

TypeMock Challenges

Future Plans

(4)

Introduction

Unit testing Integration testing

Agenda

Software testing

Automated functional testing

Software testing

Types

Functional testing

Performance testing

Usability testing

etc.

Functional testing

Manual testing

(5)

Introduction

Unit testing Integration testing

Agenda Software testing

Automated functional testing

Automated functional testing

Extent

Unit testing (Units in isolation)

Integration testing (Interaction between Modules)

System testing (All components)

(6)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 1

Using a testing framework and writing a unit test

Write tests before implementation

Testing is easy and fun

(7)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 1

Using a testing framework and writing a unit test

Write tests before implementation

(8)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

Dependency inversion

Goal

Decouple high-level components from low-level components

Patterns

Plugin

Service Locator

Dependency Injection

others?

(9)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 2

Dependency inversion

Use of patterns and interfaces can make testing easier

Fakes vs. Stubs

(10)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 2

Dependency inversion

Use of patterns and interfaces can make testing easier

Fakes vs. Stubs

(11)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

Test Doubles

Fake (Simple implemnetation)

1 p u b l i c int M e t h o d () { r e t u r n 0; }

Stub (Records information)

1 p u b l i c int M e t h o d () { M e t h o d C a l l e d = t r u e; r e t u r n 0; }

Mock (Pre-programmed expectations)

(12)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 3

Writing a mocking framework

(13)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 3

Writing a mocking framework

(14)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 4

Using a mocking framework

(15)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 4

Using a mocking framework

(16)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

Limitations of inheritance based mocking

Sealed classes

Non virtual methods

Static methods

(17)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

TypeMock Isolator

Hooks into the CLR profile API and injects code runtime.

TypeMock API

1 var web = I s o l a t e . F a k e . I n s t a n c e < SPWeb > ( ) ;

2 I s o l a t e . S w a p . A l l I n s t a n c e s < SPWeb > ( ) . W i t h ( web );

3 I s o l a t e . S w a p . N e x t I n s t a n c e < SPWeb > ( ) . W i t h ( web );

4 I s o l a t e . N o n P u b l i c . W h e n C a l l e d ( web , " I n v a l i d a t e " ).

5 D o I n s t e a d ( c o n t e x t = > { r e t u r n; });

6 I s o l a t e . S w a p . C a l l s O n ( a ). W i t h C a l l s T o ( b );

Criticism: Too powerful

(18)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 5

Testing an SharePoint application

MVP Pattern

Service Locator Pattern

TypeMock Isolator API

(19)

Introduction Unit testing Integration testing Dependency inversion Mocking TypeMock Isolator

DEMO 5

Testing an SharePoint application

MVP Pattern

Service Locator Pattern

TypeMock Isolator API

(20)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

Comparison

Unit

Integration

System

Speed

Fast

Medium

Slow

Mocking

Every

Some

None

Wrinting

Hard

Medium

Easy

(21)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

Integration testing

Approaches

Big Bang

Top-Down

Button-Up

Goals

Independent

Fast

Reproducible

(22)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

First thoughts

New farm for each test

1

Reinstall script

2

VMware Snapshots

Concerns: cumbersome and slow

Mock SharePoint

1

Middle layer/SharePoint Repository

(23)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

Using Typemock Isolator for Integration Tests

1

1 u s i n g(var s i t e = new S P S i t e ( " h t t p :// i n t e g r a t i o n - test - s i t e " )

2 { 3 I s o l a t e . W h e n C a l l e d (()= > S P F a r m . L o c a l ). W i l l R e t u r n ( 4 s i t e . W e b A p p l i c a t i o n . F a r m ); 5 6 var c o n t e x t = S P C o n t e x t . G e t C o n t e x t ( s i t e ); 7 I s o l a t e . W h e n C a l l e d (()= > S P C o n t e x t . C u r r e n t ). W i l l R e t u r n ( c o n t e x t ); 8 9 // Arrange , Act , A s s e r t 10 }

(24)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

SharePoint Integration Testing

Making the Split:

(25)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

SharePoint Integration Testing

Making the Split:

(26)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

SharePoint Configuration Database

1 [ G u i d ( " 3 B60B328 - F4D6 -4902 - BEC6 - E 9 0 4 1 7 9 F A 2 4 6 " )] 2 p u b l i c c l a s s S P P e r s i s t e d O b j e c t : ... 3 { 4 [ P e r s i s t e d ] 5 p r i v a t e H a s h t a b l e m _ P r o p e r t i e s ; 6 ... 1 < O b j e c t Id = " 2 6 9 0 8 0 da -0041 -4 b34 - 9 1 7 c - . . . " 2 C l a s s I d = " 674 da553 - ea77 -44 a3 - b9f8 - . . . " 3 P a r e n t I d = " 2 6 9 0 8 0 da -0041 -4 b34 - 9 1 7 c - . . . " 4 N a m e = " T y p e M o c k F a r m " ... > 5 < P r o p e r t i e s > 6 < o b j e c t t y p e = " ... S P F a r m ... " > 7 ... 8 < fld n a m e = " m _ P r o p e r t i e s " t y p e = " n u l l " / > 9 ... 10 < / o b j e c t > 11 < / P r o p e r t i e s > 12 < / O b j e c t >

(27)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

SharePoint Configuration Database

1 [ G u i d ( " 3 B60B328 - F4D6 -4902 - BEC6 - E 9 0 4 1 7 9 F A 2 4 6 " )] 2 p u b l i c c l a s s S P P e r s i s t e d O b j e c t : ... 3 { 4 [ P e r s i s t e d ] 5 p r i v a t e H a s h t a b l e m _ P r o p e r t i e s ; 6 ... 1 < O b j e c t Id = " 2 6 9 0 8 0 da -0041 -4 b34 - 9 1 7 c - . . . " 2 C l a s s I d = " 674 da553 - ea77 -44 a3 - b9f8 - . . . " 3 P a r e n t I d = " 2 6 9 0 8 0 da -0041 -4 b34 - 9 1 7 c - . . . " 4 N a m e = " T y p e M o c k F a r m " ... > 5 < P r o p e r t i e s > 6 < o b j e c t t y p e = " ... S P F a r m ... " > 7 ... 8 < fld n a m e = " m _ P r o p e r t i e s " t y p e = " n u l l " / > 9 ... 10 < / o b j e c t > 11 < / P r o p e r t i e s > 12 < / O b j e c t >

(28)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

SharePoint Configuration Database

1 [ G u i d ( " 3 B60B328 - F4D6 -4902 - BEC6 - E 9 0 4 1 7 9 F A 2 4 6 " )] 2 p u b l i c c l a s s S P P e r s i s t e d O b j e c t : ... 3 { 4 [ P e r s i s t e d ] 5 p r i v a t e H a s h t a b l e m _ P r o p e r t i e s ; 6 ... 1 < O b j e c t Id = " 2 6 9 0 8 0 da -0041 -4 b34 - 9 1 7 c - . . . " 2 C l a s s I d = " 674 da553 - ea77 -44 a3 - b9f8 - . . . " 3 P a r e n t I d = " 2 6 9 0 8 0 da -0041 -4 b34 - 9 1 7 c - . . . " 4 N a m e = " T y p e M o c k F a r m " ... > 5 < P r o p e r t i e s > 6 < o b j e c t t y p e = " ... S P F a r m ... " > 7 ...

(29)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

TypeMock Challenges

Faking internal types

1 p u b l i c s t a t i c o b j e c t I n s t a n c e ( 2 t h i s I F a k e r faker , 3 T y p e t , 4 M e m b e r s b e h a v i o r ) 5 { 6 var f a k e r T y p e = t y p e o f( I F a k e r ); 7 var m e t h o d = f a k e r T y p e . G e t M e t h o d ( " I n s t a n c e " , 8 new[] { t y p e o f( M e m b e r s ) }); 9 var g e n e r i c M e t h o d = m e t h o d . M a k e G e n e r i c M e t h o d ( t ); 10 r e t u r n g e n e r i c M e t h o d . I n v o k e ( I s o l a t e . Fake , 11 new o b j e c t[] { b e h a v i o r }); 12 }

(30)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

TypeMock Challenges

Dynamic new behavior, interception

1 u s i n g T y p e M o c k . I n t e r n a l . H o o k s ; 2 3 E v e n t T u n n e l . S h o u l d I n t e r c e p t D e c i s i o n = S h o u l d I n t e r c e p t D e c i s i o n ; 4 E v e n t T u n n e l . D u r i n g M e t h o d C a l l = D u r i n g M e t h o d C a l l ; 1 p r i v a t e s t a t i c v o i d S h o u l d I n t e r c e p t D e c i s i o n ( 2 T M S h o u l d I n t e r c e p t E v e n t A r g s e v e n t A r g s ) 3 { 4 e v e n t A r g s . R e t u r n s ( I n t e r c e p t B e h a v i o r . L e t I s o l a t o r D e c i d e ); 5 6 if ( e v e n t A r g s . M e t h o d N a m e == " . c t o r " ) 7 {

(31)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

TypeMock Challenges

Dynamic new behavior, swapping

1 p r i v a t e s t a t i c v o i d D u r i n g M e t h o d C a l l ( 2 T M D u r i n g C a l l E v e n t A r g s e v e n t A r g s ) 3 { 4 if ( e v e n t A r g s . M e t h o d N a m e == " . c t o r " ) 5 { 6 D i s a b l e E v e n t F i r i n g (); 7 8 var obj = ... // M o c k e d o b j e c t 9 10 E n a b l e E v e n t F i r i n g (); 11 12 S w a p . C a l l s O n ( e v e n t A r g s . C o n t e x t ). W i t h C a l l s T o ( obj ); 13 14 e v e n t A r g s . R e t u r n s ( I s o l a t i o n B e h a v i o r . S k i p M e t h o d ); 15 }

(32)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

DEMO 6

Testing an SharePoint application in-memory

(33)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

DEMO 6

Testing an SharePoint application in-memory

(34)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

Current Status & Future Plans

Current status

Can read most objects from the configuration database

Found 3 bugs in TypeMock during development, none fixed

The bugs prevent me from Update() and SPSite lookup

Future Plans (if I get time)

Do Update() and SPSite lookup

Model the content databases

Mock the timer services?

(35)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

Pex - Automated White box Testing for .NET

Peli de Halleux and Nikolai Tillmann: Unit Testing SharePoint

Services with Pex

2

Moles

1 M S P S i t e . N e w S t r i n g = ( site , _ u r l ) = > { 2 new M S P S i t e ( s i t e ) { 3 O p e n W e b = () = > new M S P W e b () { 4 D i s p o s e = () = > { } , 5 L i s t s G e t = () = > new M S P L i s t C o l l e c t i o n () { 6 // ... 7 }. I n s t a n c e 8 }. I n s t a n c e 9 }; 10 };

(36)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

Pex - Automated White box Testing for .NET

Peli de Halleux and Nikolai Tillmann: Unit Testing SharePoint

Services with Pex

2

Moles

1 M S P S i t e . N e w S t r i n g = ( site , _ u r l ) = > { 2 new M S P S i t e ( s i t e ) { 3 O p e n W e b = () = > new M S P W e b () { 4 D i s p o s e = () = > { } , 5 L i s t s G e t = () = > new M S P L i s t C o l l e c t i o n () { 6 // ... 7 }. I n s t a n c e 8 }. I n s t a n c e 9 };

(37)

Introduction Unit testing Integration testing Considerations TypeMock Challenges Future Plans

End

Questions?

References

Related documents

Call a licensed electrician or D*R*HORTON Customer Service Department if your home is still covered under the Limited Warranty.. If the power is lost throughout your home,

1 Legal and Tax Advice rendered by associated partner

As the name implies, this menu allows you to take point data in a shapefile and create gridfiles where each grid cell takes a value calculated based on the points that are

Participation based upon informed synthesis of reading material (assigned as well as other retrieved information by the students from relevant publications) is

Table 1: Mean ultrasonographic measurements of cross sectional area at various levels of the median nerve in both carpal tunnel syndrome patients and controls... Neurology Asia

ICO, Hospital Universitario Germans Trias i Pujol, Badalona (Barcelona) 08:45 -09:55 SESSION 7: MOLECULAR SCREENING. FOR SYNTHETIC

On May 6, 2011, a coalition put together by NAR, including the Community Associations Institute (CAI), the Institute for Real Estate Management (IREM), and the National Association

On target zones does not include shots saved that were