Your SlideShare is downloading. ×
0
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Automated Testing Of EPiServer CMS Sites
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Automated Testing Of EPiServer CMS Sites

3,570

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,570
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
37
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Automated testing of EPiServer CMS sitesAn overview of testing in general and specifically EPiServer sites<br />
  • 2. About me<br />Joel Abrahamsson<br />Living in Stockholm<br />Works at Valtech<br />Develops websites with ASP.NET and EPiServer<br />Blogs about web development<br />Founder of the open source projects Page Type Builder, EPiAbstractions and co-founder of EPiMVP<br />
  • 3. Agenda<br />The importance of automation<br />Types of testing<br />xUnit testing<br />Isolating code<br />Challenges when testing EPiServer sites<br />
  • 4. The importance of automation<br />Quick feedback loops<br />Less debugging<br />Limits the human factor<br />Documentation<br />
  • 5. Automation goals<br />We want our tests to be run. Often. By everyone.<br />Tests should be self-checking<br />Tests should be repeatable<br />Tests should be independent of environment<br />Tests should run fast<br />There should be no hassle running our tests.<br />
  • 6. Types of automated tests<br />UI Tests<br />Integration tests<br />Unit tests<br />
  • 7. UI Testing<br />Tests all layers of the application<br />Frameworks<br />Selenium<br />Watin/Watir<br />Can be run using a GUIor as part of xUnit tests<br />Pros<br />Concrete/easy to understand<br />Easy to get started<br />Cons<br />Very slow<br />Hard to maintain<br />Blunt feedback<br />Use for a few key scenarios or when refactoring for testability<br />Write maintainable tests using Page Objects<br />User interface<br />Business logic<br />Data access<br />Database<br />
  • 8. Tests several layers of the application<br />Implemented using Xunit frameworks<br />Pros<br />No isolation required<br />Ensures that whole features work<br />Cons<br />Slow<br />Doesn’t give very accurate feedback<br />Hard to maintain and set up<br />Use to verify functionality of interactions<br />Don’t confuse with unit tests<br />Integration Testing<br />User interface<br />Business logic<br />Data access<br />Database<br />
  • 9. Tests individual units in the system<br />Implemented using Xunit frameworks<br />Pros<br />Fast<br />Precise feedback<br />Can be used to drive developmentand ensure good design<br />Cons<br />Requires isolation/mocking<br />Use to drive development to ensure good design and provide documentation<br />Write tests for design and documentation, not quality assurance<br />Unit Testing<br />User interface<br />Business logic<br />Data access<br />Database<br />
  • 10. The common name for a set of code-driven testing frameworks<br />Test Fixtures<br />Test Suites<br />Assertions<br />Test consists of four phases<br />Set up<br />Exercise<br />Verify<br />Tear down<br />xUnit<br />
  • 11. The verification phase consists of one or several assertions<br />Tests either test state or interactions<br />Verifying state means checking a returned value or ensuring that an object is in a specific state<br />Verifying interactions usually means verifying that the component being tested has performed an interaction with another component. <br />xUnit - Asserts<br />
  • 12. Frameworks<br />NUnit<br />MBUnit<br />xUnit.net<br />Visual Studio Unit Testing Framework / MSTest<br />Executed using test runners on clients and by build servers<br />Many frameworks comes with built in runners<br />Resharper<br />TestDriven.NET<br />xUnit Frameworks<br />
  • 13. Replace a depency with a different component with the same interface to enable and verify interactions<br />Also known as mocking<br />Accomplished using Inversion of Control<br />Replacing interface methods or virtual methods<br />Frameworks<br />Rhino Mocks<br />Moq<br />Isolator<br />NUnit.Mocks<br />Code Isolation<br />
  • 14. Allow a consumer to consume a component without knowing the specifics and origins of the component in advance<br />Implement using Dependency Injection or Service Locator<br />Inversion of Control<br />
  • 15. Inversion of Control – An example<br />
  • 16. Using IoC leads to flexible components<br />Using IoC helps us conform to the SOLID principles <br />The Dependency Inversion Principle - Depend on abstractions, not on concretions<br />The Single Responsibility Principle - A class should have one, and only one, reason to change<br />IoC leads to good design<br />
  • 17. The consumer of the consumer provides the consumer with the component it depends upon<br />Constructor Injection<br />Property Injection<br />Dependency Injection<br />
  • 18. The consumer retrieves the component it depends upon from a third party, a Service Locator<br />Use Dependency Injection instead if you can<br />Service Locator<br />
  • 19. Frameworks for managing dependencies<br />Enable life cycle aware applications<br />A wide range of open source frameworks<br />StructureMap<br />Ninject<br />Unity<br />Castle Windsor<br />Autofac<br />IoC Containers<br />
  • 20. Test Doubles<br />Dummies – objects that are passed around but never used.<br />Fakes – Working implementations<br />Stubs – Provides implementations for certain methods with responses defined in the test<br />Mocks – Same as stubs but with expectations that can be verified<br />Partial mocks<br />Isolation/Mocking terminology<br />
  • 21. Static or non-virtual methods<br />Example: all methods in DataFactory are non-virtual<br />Makes Inversion of Control hard<br />Dependent on it’s configuration<br />Makes it hard to test single units of code<br />Tightly integrated with Web Forms<br />Makes it hard to test without a HTTP Context<br />Complicates Depency Injection<br />EPiServer CMS challenges<br />
  • 22. Create wrappers<br />EPiAbstractions<br />epiabstractions.codeplex.com<br />Beware of security concerns<br />Overcoming static and non-virtual methods<br />
  • 23. Create wrappers<br />Use Page Type Builder to decouple from PageData.Property<br />Partial mocking<br />Overcoming dependencies on the configuration<br />
  • 24. Extract business logic from pages and controls<br />Use Page Type Builder to decouple from PageData.Property<br />pagetypebuilder.codeplex.com<br />The Model View Presenter pattern<br />Web Forms MVP<br />webformsmvp.com<br />EPiMVP<br />github.com/joelabrahamsson/EPiServer-MVP<br />Overcoming tight Web Forms integration<br />
  • 25. Model View Presenter<br />Image from http://geekswithblogs.net/dchristiansen/archive/2007/12/07/microsoft-patterns-and-practices-team-release-the-model-view-presenter.aspx<br />
  • 26. Two base classes for pages and controls, EPiMvpPage and EPiMvpUserControl<br />A base class for presenters, EPiPresenter<br />A presenterfactory that instantiates presenters for views with the view and PageData object<br />Also comes with two presenterfactories that utilizes IoC containers, StructureMap and Ninject<br />EPiMVP - Components<br />
  • 27. A request comes in to the view<br />Web Forms MVP inspects the views PresenterBinding attribute to find the presenter type<br />Web Forms MVP uses a configured (in global.asax) PresenterFactory to instantiate a presenter with a modelobject<br />The presenter, which receives the view and PageData object in the constructor attaches it’s methods to the view’s events<br />EPiMVP – How it works<br />
  • 28. Good candidates for testing include<br />Integrations with external services<br />Utilities (AddQuerystringParameter etc)<br />Custom caching<br />Components that easily get to be complex (example: paging)<br />Bad candidates include<br />Components with extremely little logic<br />Components where the logic is handled by EPiServer (menus etc)<br />Components that deal with, or are closely coupled to, markup <br />Keep in mind that the point of the test isn’t only what it tests but that it drives good design<br />What to (not) test using unit tests<br />
  • 29. Give your tests descriptive names<br />Care about the code in your test<br />Arrange your tests using AAA (Arrange, Act, Assert)<br />Also known as Given-When-Then<br />Be carefull with using code coverage as a measurement<br />Some principles such as the DRY principle isn’t always valid for tests<br />Do not use tools to generate tests. Period.<br />Words of advice<br />
  • 30. Questions?<br />http://joelabrahamsson.com<br />@joelabrahamsson<br />mail@joelabrahamsson.com<br />

×