SlideShare a Scribd company logo
Unit Testing in
SharePoint 2010
      Chris Weldon
   Dallas TechFest 2011
Before We Begin


http://slidesha.re/       http://spkr8.com/t/8140




git://github.com/neraath/testing-in-sp2010.git
Your Guide: Chris Weldon

•   Fightin’ Texas Aggie

•   .Net and PHP Developer

•   UNIX and Windows Sysadmin

•   Sr. Consultant at Improving Enterprises

•   chris@chrisweldon.net
Agile, Microsoft, Open Technologies, UX
Applied Training, Coaching, Mentoring
Certified Consulting
Rural Sourcing
Recruiting Services
Assumptions


• You develop software
• You unit test
• You know the SharePoint API (or can follow along)
Standard Testing Practices
                        A Common Problem
namespace SharePointLogic
{
    public class ClassWithDependencies
    {
        private IDataRepository repository;

        public ClassWithDependencies(IDataRepository repo)
        {
            this.repository = repo;
        }

        public INode GetNodeByName(string name)
        {
            return this.repository.Where(x => x.Name.Equals(name))
                                  .Select();
        }
    }
}
public IList<SPUser> GetUsersInSiteCollection(string siteUrl) {
  using (SPSite site = new SPSite(siteUrl) {
    site.CatchAccessDeinedError = false;

        using (SPWeb web = site.RootWeb) {
          try {
            if (web.DoesUserHavePermissions(SPBasePermissions.ManageWeb)) {
              SPUsercollection users = web.Users;
              List<SPUser> usersWithAccess = new List<SPUser>();
              foreach (SPUser user in users) {
                if (web.DoesUserHavePermissions(
                  user.LoginName, SPBasePermissions.ManageWeb)) {
                  usersWithAccess.Add(user);
                }
              }

                return usersWithAccess;
              }
            } catch (UnauthorizedAccessException e) {
              return new List<SPUser>();
            }
        }
    }
}
Standard Testing Practices
                A Common Problem



• What if no database locally?
• Did you write test logic to rebuild the database
  before each test run?

• What if this dependency is a physical piece of
  hardware?
Standard Testing Practices
                               How to Solve
namespace SharePointLogicTests
{
    [TestClass]
    public class ClassWithDependenciesTests
    {
        [TestMethod]
        public void TestGetNodesByName()
        {
            // Arrange.
            INode node = new SharePointNode();
            IDataRepository repository =
                (IDataRepository)MockRepository.Stub<IDataRepository>();
            repository.Stub(x => x.Where).Returns(repository);
            repository.Stub(x => x.Select).Returns(node);
            repository.Replay();

// ...
Standard Testing Practices
                                 How to Solve


            // Act.
            ClassWithDependencies testClass = new ClassWithDependencies(repository);
            INode testNode = testClass.GetNodeByName("Test");

            // Assert.
            Assert.AreEqual(node, testNode);
        }
    }
}
Standard Testing Practices
              What about SharePoint?


• Most of SharePoint object model has NO interfaces
• Worse, most also are Sealed classes, meaning no
  extending and overriding the SharePoint behavior

• Most SharePoint objects require active connection
  and instance of SharePoint on local server

 • Unlike database projects, resetting and recreating
    state in SharePoint is way more difficult
Standard Testing Practices
          A SharePoint Common Problem


public string GetNameOfSharePointWebSite(string url)
{
    using (SPSite site = new SPSite(url))
    {
        using (SPWeb web = site.OpenWeb())
        {
            return web.Name;
        }
    }
}
Pex and Moles
• What is it?
 • Pex discovers boundary conditions of your tests
    and automates test creation

 • Visual Studio Add In
 • Developed by Microsoft Research
 • Available for Academic or for MSDN subscribers
Pex and Moles

• Moles is, simply put, a mocking and stubbing
  framework

 • Different than other traditional mocking
    frameworks

 • Uses detours to custom delegates via runtime
    instrumentation
Pex and Moles


• Pex and Moles are not mutually exclusive
• Neither are dependent upon one another
DEMO

SharePoint & Moles
     Example
Pex and Moles
• As your dependency on SharePoint Object Model
  grows, more detours required for testing

• In most cases, more tedious than beneficial
• If only could have most of the basic SharePoint
  behaviors pre-generated

• Solution:
  Microsoft.SharePoint.Behaviors
DEMO

SharePoint Mole
   Behaviors
Observations
Observations
• Even behaviors are not complete
Observations
• Even behaviors are not complete
• A lot of mocking activity may get repeated
Observations
• Even behaviors are not complete
• A lot of mocking activity may get repeated
• Unit test setup logic gets refactored into common
  assemblies
Observations
• Even behaviors are not complete
• A lot of mocking activity may get repeated
• Unit test setup logic gets refactored into common
  assemblies

• Save time: create scenarios
Observations
• Even behaviors are not complete
• A lot of mocking activity may get repeated
• Unit test setup logic gets refactored into common
  assemblies

• Save time: create scenarios
• Use BDD-style approach for testing
Gotchas
Gotchas
• More moles unit tests = much longer test execution
  time
Gotchas
• More moles unit tests = much longer test execution
  time

• Continuous Integration
Gotchas
• More moles unit tests = much longer test execution
  time

• Continuous Integration
• This will take time to learn, research, and debug
Gotchas
• More moles unit tests = much longer test execution
  time

• Continuous Integration
• This will take time to learn, research, and debug
 • Pay attention when it stops adding value
Gotchas
• More moles unit tests = much longer test execution
  time

• Continuous Integration
• This will take time to learn, research, and debug
 • Pay attention when it stops adding value
• The GAC
Gotchas
• More moles unit tests = much longer test execution
  time

• Continuous Integration
• This will take time to learn, research, and debug
 • Pay attention when it stops adding value
• The GAC
Recommendations
Recommendations

• If you can do it, build a facade in front of SharePoint
Recommendations

• If you can do it, build a facade in front of SharePoint
• Make sure you are producing consistent behaviors
Recommendations

• If you can do it, build a facade in front of SharePoint
• Make sure you are producing consistent behaviors
 • If you don’t know what SharePoint does,
    disassemble it
Q&A
Thank You!


http://slidesha.re/       http://spkr8.com/t/8140




git://github.com/neraath/testing-in-sp2010.git

More Related Content

What's hot

Introduction to jest
Introduction to jestIntroduction to jest
Introduction to jest
pksjce
 
2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches
Nicolas Fränkel
 
Quickly testing legacy code
Quickly testing legacy codeQuickly testing legacy code
Quickly testing legacy code
Clare Macrae
 
How to Un-Flake Flaky Tests - A New Hire's Toolkit
How to Un-Flake Flaky Tests - A New Hire's ToolkitHow to Un-Flake Flaky Tests - A New Hire's Toolkit
How to Un-Flake Flaky Tests - A New Hire's Toolkit
Zachary Attas
 
Adding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipelineAdding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipeline
Eduardo Piairo
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
Mini training - Moving to xUnit.net
Mini training - Moving to xUnit.netMini training - Moving to xUnit.net
Mini training - Moving to xUnit.net
Betclic Everest Group Tech Team
 
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Steven Smith
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven Smith
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
Dave Haeffner
 
Quickly Testing Legacy Code - ACCU York April 2019
Quickly Testing Legacy Code - ACCU York April 2019Quickly Testing Legacy Code - ACCU York April 2019
Quickly Testing Legacy Code - ACCU York April 2019
Clare Macrae
 
Mini-Training: NFluent
Mini-Training: NFluentMini-Training: NFluent
Mini-Training: NFluent
Betclic Everest Group Tech Team
 
Automated Software Testing
Automated Software TestingAutomated Software Testing
Automated Software Testing
arild2
 
Testing JSF with Arquillian and Selenium
Testing JSF with Arquillian and SeleniumTesting JSF with Arquillian and Selenium
Testing JSF with Arquillian and Selenium
Lukáš Fryč
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
Steve Upton
 
Faking Hell
Faking HellFaking Hell
Faking Hell
Giovanni Asproni
 
Functional tests for dummies
Functional tests for dummiesFunctional tests for dummies
Functional tests for dummies
cpsitgmbh
 
DSR Microservices (Day 1, Part 2)
DSR Microservices (Day 1, Part 2)DSR Microservices (Day 1, Part 2)
DSR Microservices (Day 1, Part 2)
Steve Upton
 
Implementing Quality on a Java Project
Implementing Quality on a Java ProjectImplementing Quality on a Java Project
Implementing Quality on a Java Project
Vincent Massol
 
DSR Testing (Part 2)
DSR Testing (Part 2)DSR Testing (Part 2)
DSR Testing (Part 2)
Steve Upton
 

What's hot (20)

Introduction to jest
Introduction to jestIntroduction to jest
Introduction to jest
 
2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches2014 Joker - Integration Testing from the Trenches
2014 Joker - Integration Testing from the Trenches
 
Quickly testing legacy code
Quickly testing legacy codeQuickly testing legacy code
Quickly testing legacy code
 
How to Un-Flake Flaky Tests - A New Hire's Toolkit
How to Un-Flake Flaky Tests - A New Hire's ToolkitHow to Un-Flake Flaky Tests - A New Hire's Toolkit
How to Un-Flake Flaky Tests - A New Hire's Toolkit
 
Adding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipelineAdding unit tests with tSQLt to the database deployment pipeline
Adding unit tests with tSQLt to the database deployment pipeline
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Mini training - Moving to xUnit.net
Mini training - Moving to xUnit.netMini training - Moving to xUnit.net
Mini training - Moving to xUnit.net
 
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
Breaking Dependencies to Allow Unit Testing - DevIntersection Spring 2016
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
How To Use Selenium Successfully
How To Use Selenium SuccessfullyHow To Use Selenium Successfully
How To Use Selenium Successfully
 
Quickly Testing Legacy Code - ACCU York April 2019
Quickly Testing Legacy Code - ACCU York April 2019Quickly Testing Legacy Code - ACCU York April 2019
Quickly Testing Legacy Code - ACCU York April 2019
 
Mini-Training: NFluent
Mini-Training: NFluentMini-Training: NFluent
Mini-Training: NFluent
 
Automated Software Testing
Automated Software TestingAutomated Software Testing
Automated Software Testing
 
Testing JSF with Arquillian and Selenium
Testing JSF with Arquillian and SeleniumTesting JSF with Arquillian and Selenium
Testing JSF with Arquillian and Selenium
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
Faking Hell
Faking HellFaking Hell
Faking Hell
 
Functional tests for dummies
Functional tests for dummiesFunctional tests for dummies
Functional tests for dummies
 
DSR Microservices (Day 1, Part 2)
DSR Microservices (Day 1, Part 2)DSR Microservices (Day 1, Part 2)
DSR Microservices (Day 1, Part 2)
 
Implementing Quality on a Java Project
Implementing Quality on a Java ProjectImplementing Quality on a Java Project
Implementing Quality on a Java Project
 
DSR Testing (Part 2)
DSR Testing (Part 2)DSR Testing (Part 2)
DSR Testing (Part 2)
 

Viewers also liked

Unit Testing SharePoint Applications
Unit Testing SharePoint ApplicationsUnit Testing SharePoint Applications
Unit Testing SharePoint Applications
Gil Zilberfeld
 
Managesp 160805190411
Managesp 160805190411Managesp 160805190411
Managesp 160805190411
Danielle Jennings
 
Risk Management in SharePoint Governance
Risk Management in SharePoint GovernanceRisk Management in SharePoint Governance
Risk Management in SharePoint Governance
Christian Buckley
 
V Greavu - Testing with Sharepoint
V Greavu - Testing with SharepointV Greavu - Testing with Sharepoint
V Greavu - Testing with Sharepoint
TestCampRO
 
Case Study for a SharePoint SDLC
Case Study for a SharePoint SDLCCase Study for a SharePoint SDLC
Case Study for a SharePoint SDLC
Marie-Michelle Strah, PhD
 
Agile SharePoint Development With Scrum
Agile SharePoint Development With ScrumAgile SharePoint Development With Scrum
Agile SharePoint Development With Scrum
Andrew Woodward
 
Information architecture and SharePoint
Information architecture and SharePointInformation architecture and SharePoint
Information architecture and SharePoint
Lulu Pachuau
 
An SDLC for SharePoint
An SDLC for SharePointAn SDLC for SharePoint
An SDLC for SharePoint
gvaughan
 
Testing SharePoint solutions overview
Testing SharePoint solutions overviewTesting SharePoint solutions overview
Testing SharePoint solutions overview
Spiffy
 
Quality Assurance in SDLC
Quality Assurance in SDLCQuality Assurance in SDLC
Quality Assurance in SDLC
Adil Mughal
 
Deep Dive into SharePoint Topologies and Server Architecture for SharePoint 2013
Deep Dive into SharePoint Topologies and Server Architecture for SharePoint 2013Deep Dive into SharePoint Topologies and Server Architecture for SharePoint 2013
Deep Dive into SharePoint Topologies and Server Architecture for SharePoint 2013
K.Mohamed Faizal
 

Viewers also liked (11)

Unit Testing SharePoint Applications
Unit Testing SharePoint ApplicationsUnit Testing SharePoint Applications
Unit Testing SharePoint Applications
 
Managesp 160805190411
Managesp 160805190411Managesp 160805190411
Managesp 160805190411
 
Risk Management in SharePoint Governance
Risk Management in SharePoint GovernanceRisk Management in SharePoint Governance
Risk Management in SharePoint Governance
 
V Greavu - Testing with Sharepoint
V Greavu - Testing with SharepointV Greavu - Testing with Sharepoint
V Greavu - Testing with Sharepoint
 
Case Study for a SharePoint SDLC
Case Study for a SharePoint SDLCCase Study for a SharePoint SDLC
Case Study for a SharePoint SDLC
 
Agile SharePoint Development With Scrum
Agile SharePoint Development With ScrumAgile SharePoint Development With Scrum
Agile SharePoint Development With Scrum
 
Information architecture and SharePoint
Information architecture and SharePointInformation architecture and SharePoint
Information architecture and SharePoint
 
An SDLC for SharePoint
An SDLC for SharePointAn SDLC for SharePoint
An SDLC for SharePoint
 
Testing SharePoint solutions overview
Testing SharePoint solutions overviewTesting SharePoint solutions overview
Testing SharePoint solutions overview
 
Quality Assurance in SDLC
Quality Assurance in SDLCQuality Assurance in SDLC
Quality Assurance in SDLC
 
Deep Dive into SharePoint Topologies and Server Architecture for SharePoint 2013
Deep Dive into SharePoint Topologies and Server Architecture for SharePoint 2013Deep Dive into SharePoint Topologies and Server Architecture for SharePoint 2013
Deep Dive into SharePoint Topologies and Server Architecture for SharePoint 2013
 

Similar to Unit Testing in SharePoint 2010

More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
Jen Wong
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
FalafelSoftware
 
Test in action – week 1
Test in action – week 1Test in action – week 1
Test in action – week 1
Yi-Huan Chan
 
Mcknight well built extensions
Mcknight well built extensionsMcknight well built extensions
Mcknight well built extensions
Richard McKnight
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
Rob Hale
 
Performance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle CoherencePerformance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle Coherence
aragozin
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
wajrcs
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
LB Denker
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
Richard North
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
TEST Huddle
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
Ben Hall
 
Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​
Payara
 
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
garrett honeycutt
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
Jay Friendly
 
Introduction to SoapUI day 4-5
Introduction to SoapUI day 4-5Introduction to SoapUI day 4-5
Introduction to SoapUI day 4-5
Qualitest
 
Advanced Java Testing
Advanced Java TestingAdvanced Java Testing
Advanced Java Testing
Vincent Massol
 
Getting Started with Test-Driven Development at Midwest PHP 2021
Getting Started with Test-Driven Development at Midwest PHP 2021Getting Started with Test-Driven Development at Midwest PHP 2021
Getting Started with Test-Driven Development at Midwest PHP 2021
Scott Keck-Warren
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
All Things Open
 

Similar to Unit Testing in SharePoint 2010 (20)

More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
 
Breaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit TestingBreaking Dependencies to Allow Unit Testing
Breaking Dependencies to Allow Unit Testing
 
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
Breaking Dependencies To Allow Unit Testing - Steve Smith | FalafelCON 2014
 
Test in action – week 1
Test in action – week 1Test in action – week 1
Test in action – week 1
 
Mcknight well built extensions
Mcknight well built extensionsMcknight well built extensions
Mcknight well built extensions
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
 
Performance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle CoherencePerformance Test Driven Development with Oracle Coherence
Performance Test Driven Development with Oracle Coherence
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
Developer testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing FanaticDeveloper testing 101: Become a Testing Fanatic
Developer testing 101: Become a Testing Fanatic
 
Testcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentationTestcontainers - Geekout EE 2017 presentation
Testcontainers - Geekout EE 2017 presentation
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​Easy Java Integration Testing with Testcontainers​
Easy Java Integration Testing with Testcontainers​
 
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
20111110 how puppet-fits_into_your_existing_infrastructure_and_change_managem...
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 
Automated php unit testing in drupal 8
Automated php unit testing in drupal 8Automated php unit testing in drupal 8
Automated php unit testing in drupal 8
 
Introduction to SoapUI day 4-5
Introduction to SoapUI day 4-5Introduction to SoapUI day 4-5
Introduction to SoapUI day 4-5
 
Advanced Java Testing
Advanced Java TestingAdvanced Java Testing
Advanced Java Testing
 
Getting Started with Test-Driven Development at Midwest PHP 2021
Getting Started with Test-Driven Development at Midwest PHP 2021Getting Started with Test-Driven Development at Midwest PHP 2021
Getting Started with Test-Driven Development at Midwest PHP 2021
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 

More from Chris Weldon

Keat presentation
Keat presentationKeat presentation
Keat presentation
Chris Weldon
 
REST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend FrameworkREST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend Framework
Chris Weldon
 
Beyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareBeyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver Software
Chris Weldon
 
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO ProprietySOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
Chris Weldon
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
Chris Weldon
 
IoC with PHP
IoC with PHPIoC with PHP
IoC with PHP
Chris Weldon
 
PHP & MVC
PHP & MVCPHP & MVC
PHP & MVC
Chris Weldon
 

More from Chris Weldon (7)

Keat presentation
Keat presentationKeat presentation
Keat presentation
 
REST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend FrameworkREST Easy - Building RESTful Services in Zend Framework
REST Easy - Building RESTful Services in Zend Framework
 
Beyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver SoftwareBeyond TDD: Enabling Your Team to Continuously Deliver Software
Beyond TDD: Enabling Your Team to Continuously Deliver Software
 
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO ProprietySOLID - Not Just a State of Matter, It's Principles for OO Propriety
SOLID - Not Just a State of Matter, It's Principles for OO Propriety
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 
IoC with PHP
IoC with PHPIoC with PHP
IoC with PHP
 
PHP & MVC
PHP & MVCPHP & MVC
PHP & MVC
 

Recently uploaded

WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 

Recently uploaded (20)

WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 

Unit Testing in SharePoint 2010

  • 1. Unit Testing in SharePoint 2010 Chris Weldon Dallas TechFest 2011
  • 2. Before We Begin http://slidesha.re/ http://spkr8.com/t/8140 git://github.com/neraath/testing-in-sp2010.git
  • 3. Your Guide: Chris Weldon • Fightin’ Texas Aggie • .Net and PHP Developer • UNIX and Windows Sysadmin • Sr. Consultant at Improving Enterprises • chris@chrisweldon.net
  • 4. Agile, Microsoft, Open Technologies, UX Applied Training, Coaching, Mentoring Certified Consulting Rural Sourcing Recruiting Services
  • 5. Assumptions • You develop software • You unit test • You know the SharePoint API (or can follow along)
  • 6. Standard Testing Practices A Common Problem namespace SharePointLogic { public class ClassWithDependencies { private IDataRepository repository; public ClassWithDependencies(IDataRepository repo) { this.repository = repo; } public INode GetNodeByName(string name) { return this.repository.Where(x => x.Name.Equals(name)) .Select(); } } }
  • 7. public IList<SPUser> GetUsersInSiteCollection(string siteUrl) { using (SPSite site = new SPSite(siteUrl) { site.CatchAccessDeinedError = false; using (SPWeb web = site.RootWeb) { try { if (web.DoesUserHavePermissions(SPBasePermissions.ManageWeb)) { SPUsercollection users = web.Users; List<SPUser> usersWithAccess = new List<SPUser>(); foreach (SPUser user in users) { if (web.DoesUserHavePermissions( user.LoginName, SPBasePermissions.ManageWeb)) { usersWithAccess.Add(user); } } return usersWithAccess; } } catch (UnauthorizedAccessException e) { return new List<SPUser>(); } } } }
  • 8. Standard Testing Practices A Common Problem • What if no database locally? • Did you write test logic to rebuild the database before each test run? • What if this dependency is a physical piece of hardware?
  • 9. Standard Testing Practices How to Solve namespace SharePointLogicTests { [TestClass] public class ClassWithDependenciesTests { [TestMethod] public void TestGetNodesByName() { // Arrange. INode node = new SharePointNode(); IDataRepository repository = (IDataRepository)MockRepository.Stub<IDataRepository>(); repository.Stub(x => x.Where).Returns(repository); repository.Stub(x => x.Select).Returns(node); repository.Replay(); // ...
  • 10. Standard Testing Practices How to Solve // Act. ClassWithDependencies testClass = new ClassWithDependencies(repository); INode testNode = testClass.GetNodeByName("Test"); // Assert. Assert.AreEqual(node, testNode); } } }
  • 11. Standard Testing Practices What about SharePoint? • Most of SharePoint object model has NO interfaces • Worse, most also are Sealed classes, meaning no extending and overriding the SharePoint behavior • Most SharePoint objects require active connection and instance of SharePoint on local server • Unlike database projects, resetting and recreating state in SharePoint is way more difficult
  • 12. Standard Testing Practices A SharePoint Common Problem public string GetNameOfSharePointWebSite(string url) { using (SPSite site = new SPSite(url)) { using (SPWeb web = site.OpenWeb()) { return web.Name; } } }
  • 13. Pex and Moles • What is it? • Pex discovers boundary conditions of your tests and automates test creation • Visual Studio Add In • Developed by Microsoft Research • Available for Academic or for MSDN subscribers
  • 14. Pex and Moles • Moles is, simply put, a mocking and stubbing framework • Different than other traditional mocking frameworks • Uses detours to custom delegates via runtime instrumentation
  • 15. Pex and Moles • Pex and Moles are not mutually exclusive • Neither are dependent upon one another
  • 17. Pex and Moles • As your dependency on SharePoint Object Model grows, more detours required for testing • In most cases, more tedious than beneficial • If only could have most of the basic SharePoint behaviors pre-generated • Solution: Microsoft.SharePoint.Behaviors
  • 18. DEMO SharePoint Mole Behaviors
  • 21. Observations • Even behaviors are not complete • A lot of mocking activity may get repeated
  • 22. Observations • Even behaviors are not complete • A lot of mocking activity may get repeated • Unit test setup logic gets refactored into common assemblies
  • 23. Observations • Even behaviors are not complete • A lot of mocking activity may get repeated • Unit test setup logic gets refactored into common assemblies • Save time: create scenarios
  • 24. Observations • Even behaviors are not complete • A lot of mocking activity may get repeated • Unit test setup logic gets refactored into common assemblies • Save time: create scenarios • Use BDD-style approach for testing
  • 26. Gotchas • More moles unit tests = much longer test execution time
  • 27. Gotchas • More moles unit tests = much longer test execution time • Continuous Integration
  • 28. Gotchas • More moles unit tests = much longer test execution time • Continuous Integration • This will take time to learn, research, and debug
  • 29. Gotchas • More moles unit tests = much longer test execution time • Continuous Integration • This will take time to learn, research, and debug • Pay attention when it stops adding value
  • 30. Gotchas • More moles unit tests = much longer test execution time • Continuous Integration • This will take time to learn, research, and debug • Pay attention when it stops adding value • The GAC
  • 31. Gotchas • More moles unit tests = much longer test execution time • Continuous Integration • This will take time to learn, research, and debug • Pay attention when it stops adding value • The GAC
  • 33. Recommendations • If you can do it, build a facade in front of SharePoint
  • 34. Recommendations • If you can do it, build a facade in front of SharePoint • Make sure you are producing consistent behaviors
  • 35. Recommendations • If you can do it, build a facade in front of SharePoint • Make sure you are producing consistent behaviors • If you don’t know what SharePoint does, disassemble it
  • 36. Q&A
  • 37. Thank You! http://slidesha.re/ http://spkr8.com/t/8140 git://github.com/neraath/testing-in-sp2010.git

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. Our problem? Dependency on objects we don&amp;#x2019;t control. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n