SlideShare a Scribd company logo
Modern Web Development
Testable WebForms with Model View Presenter
Modern Web Development
Testable WebForms with Model View Presenter
Modern Web - MVP Testable WebForms
Modern Web - MVP Testable WebForms
Rachel
developingUX.com
speakermix.com/calebjenkins
@calebjenkins
#ttf2014
why
Testable
Repeatable
Maintainable Reliable-able
Scalable
Extensible
Deliverable
Workable
Development
Object Orientation
SOLID
Patterns
Secure Coding
Engineering
Automated Tests
Source Control
Automated Builds
Process
Agile, Lean, XP
Team Dynamics
Continuous Learning
Modern Web - MVP Testable WebForms
http://developingUX.com/TulsaTech2014/
1:30pm
3:00pm
4:00pm
#ttf2014
write better code
modern web!
back to…
15
what are the 4 big parts of unit tests?
Test Framework Test Runner
Code Tests
16
your application
what you want to test
your test code
the code that tests the
code that you wrote or are
going to write
attributes and asserts
the framework provides
the attributes and asserts
so we know what the tests
are doing.
Examples: nUnit jUnit
cppUnit
runs the tests
often associated with the
test framework; is
distinctly separate.
sometime integrated in
IDE, CI Server or stand
alone exe
Test Runner
17
Code
TestFramework
Tests
Tests
Tests
Tests
Tests
Test Runners
18
nUnit Test Runner
Visual Studio (VS Test)
CodeRush / ReSharper
Continuous Integration (Team City)
the problem with edges
UI DataBusiness
Edges are
Hard to Test
Testing edges
can be like
testing to see
if you’re good
at cliff jumping
That’s not me
..or you’re
stuff on a rock.
You’re either an
expert and it works…
UI DataData
Logic
UI
Logic
Business
Edges are
Hard to Test
Edges are still
Hard to Test
by separating UI/Data edges from
UI/Data logic we’re increasing the testable area
we’ve also made it easier to implement
various UI and Data platforms
without affecting the application logic
25
Model View Controller (MVC)
•All input is routed to a controller
•Example Web Scenarios
•ASP.NET MVC Framework
Model View Presenter (MVP)
• View initiates Presenter
• UI Logic is contained in Presenter
• Example WinForms & ASP.NET Webform apps
Model View ViewModel (MVVM)
• ViewModel is a view specific model
• VM is can mash up application models
• UI logic contained in ViewModel
• Example Rich Data binding Scenarios
(WPF / Silverlight / XAML / JS)
Definitions
Modern Web - MVP Testable WebForms
Reflects
Modern Web - MVP Testable WebForms
With MVP
the Presenter “knows” about every field.
MobileNumber
BirthDay
In a MVVM
the View “binds” to the ViewModel
Modern Web - MVP Testable WebForms
angularJS.org
handelbarsJS.com
knockoutJS.com
knockoutMVC.com ToDoMVC.com
WebForms -> MVP
WebForms -> MVP
interface IMyPageView
MyPage.aspx
class MyPage : Page, IMyPageView
event Load
bool isPostBack
string MyText
event ButtonPressed
class MyPagePresenter
MyPagePresenter
(IMyPageView view)
DetermineViewInteractions
1
implement Viewin Page
2
wire View in Presenter
3
Test Presenter
4
Did you say
Testable WebForms?
Resources & Frameworks
BDD
http://neelnarayan.blogspot.com/2010/07/bdd-is-more-than-tdd-done-right.html
more than TDD done right
http://dannorth.net/introducing-bdd/
introducing BDD
http://lucisferre.net/2011/02/05/behavior-driven-test-driven-domain-driven-design/
behavior driven, test driven, domain driven
nBehave, nSpec, SpecFlow, StoryQ,
mSpec, StorEvil
Modern Web - MVP Testable WebForms
Handle your
dependencies
Dependencies
“The single greatest thing that you can do to
make your code more testable and healthy is to
start taking a Dependency Injection approach to
writing software”
- Real World .NET, C# and Silverlight
Wrox Press 2012
Caleb Jenkins
Data Access
Data Logic
Integration Service Proxy
App Domain Domain Validation
UI Logic
UI
How do you test this
with these
dependencies
Data Access
Data Logic
Integration Service Proxy
App Domain Domain Validation
UI Logic
UI
Test Runner
Test Code
Integration Service Proxy
App Domain Domain Validation
UI Logic
Dependency Injection + Interfaces
Faked dependencies to increase unit isolation
Leverage mocking frameworks makes life better
Note:
Dependency Injection
will turn you in to a complete
coding Ninja, however the
full scope of DI with any of
the many DI frameworks is
beyond the scope of this talk
http://developingUX.com/DI/
- Real World .NET, C# and Silverlight
Wrox Press 2012
Caleb Jenkins
Mocking Framework
“A mocking framework allows you to create fake classes on the fly in-
line with your test code. That is a bit of a simplification, mocking
frameworks use a combination of emits, reflection and generics to
create run-time instance implementations of .NET Interfaces – whew,
that’s a mouthful - it’s a whole lot easier to say that they create fake
classes on the fly!”
Mocking in .NET
Microsoft.Fakes
Bringing DI together
IData mockData = MockRepository.GenerateMock<IData>();
mockData.Expect(x => x.getAll<account>())
.Return(sampleAccounts).Repeat.Once();
IAccountServices accountService
= new AcmeAccountService(mockData);
var act = accountService.GetAccount(known_account_id);
mockData.VerifyAllExpectations();
WebForms -> MVP
MyPage.aspxMyPagePresenter
Leverage DI from Here! Thin with no UI logic!
Non-Platform Specific in View Interface
WebForms -> MVP
Test the Presenter!
DI + Mocks == Awesome!
WireUp DI
5
Consider WebFormsMVP
6
6 http://WebFormsMVP.com
http://WebFormsMVP.com
Modern Web - MVP Testable WebForms
Modern Web - MVP Testable WebForms
http://www.flickr.com/photos/jforth/5768064504/
http://www.flickr.com/photos/laughingsquid/255915238/
http://www.flickr.com/photos/dieselbug2007/370557683/
http://www.flickr.com/photos/m0php/530526644/
http://www.flickr.com/photos/lowfatbrains/80542761/
http://www.flickr.com/photos/georgivar/4974112941/
http://www.flickr.com/photos/redbettyblack/395899686/sizes/
http://www.flickr.com/photos/goldberg/815408116/
http://www.flickr.com/photos/fudj/122371431/
http://www.flickr.com/photos/yardsale/4524101944/
http://www.flickr.com/photos/38738277@N04/3652658961/
http://www.flickr.com/photos/utslibrary/6776175796/
http://www.flickr.com/photos/48725518@N03/4478990651/
Copyright © Merriswheel – Used without permission
http://www.flickr.com/photos/mworrell/266913194/
https://www.flickr.com/photos/sprengben/4419536377/
Please Complete An Evaluation Form
Your input is important!
You can access Evaluation Forms at:
http://TulsaTechFest.com
Modern Web - MVP Testable WebForms
developingUX.com
speakermix.com/calebjenkins
@calebjenkins
Test Code … 3 A’s
75
Arrange– Set up the scenario and the initial input values. Often
in a common [TestFixtureSetup] or [Setup] method
Act - Action that creates the outcome that is being tests, usually
calling some method in your code to test the result.
Assert – Is a boolean statement to your testing framework to
declare the expected outcome. Results in Pass or Fail
Arrange Act Assert
Data Access
Data Logic
Integration Service Proxy
App Domain Domain Validation
UI Logic
UI
Building better Lego’s
Tests are small
Tests are fast
Tests focus on one thing
Red
GreenRefactor
Test Runner
Simple Tests (return values) with no dependencies…
App Domain Domain Validation
UI Logic
Test Code
Unit Tests focus on a Unit
Test a unit in isolation from other units
Control input => Testable output
as a <role>,
I will <function>
so that <value>
Defining Behavior
Discussion
what if our “tests”
given <class> to test
when <setup> scenario
then <test> outcome
matched our
language?
Discussion
Discussion
BDD

More Related Content

PPTX
Get your Hero Groove On - Heroes Reborn
PPTX
Coding Naked 2023
PPTX
Development Matters
PPTX
Code to DI For - Dependency Injection for Modern Applications
PPTX
Scaling Scrum with UX in the Enterprise
PPTX
10 Reasons Your Software Sucks 2014 - Tax Day Edition!
PPTX
Modern ASP.NET Webskills
PPTX
Prototype Collaborate Innovate
Get your Hero Groove On - Heroes Reborn
Coding Naked 2023
Development Matters
Code to DI For - Dependency Injection for Modern Applications
Scaling Scrum with UX in the Enterprise
10 Reasons Your Software Sucks 2014 - Tax Day Edition!
Modern ASP.NET Webskills
Prototype Collaborate Innovate

More from Caleb Jenkins (14)

PPTX
10 Reasons Your Software Sucks - Election 2012 Edition
PPTX
Windows 8 & Phone 8 - an Architectural Battle Plan
PPTX
Scaling Scrum with UX
PPTX
Coding Naked
PPTX
Scaling Scrum with UX
PPTX
Taming the Monster Legacy Code Beast
PPTX
Silverlight for Mobile World Dominations
PPTX
.NET on the Cheap - Microsoft + OSS
PPTX
10 practices that every developer needs to start right now
PPTX
Threat Modeling - Writing Secure Code
PPT
Dependency Injection in Silverlight
PPT
Becoming A Presenter in the .NET World
PPT
Silverlight 2 with Visual Studio 2008 and Expression Blend
PPT
ASP.NET AJAX with Visual Studio 2008
10 Reasons Your Software Sucks - Election 2012 Edition
Windows 8 & Phone 8 - an Architectural Battle Plan
Scaling Scrum with UX
Coding Naked
Scaling Scrum with UX
Taming the Monster Legacy Code Beast
Silverlight for Mobile World Dominations
.NET on the Cheap - Microsoft + OSS
10 practices that every developer needs to start right now
Threat Modeling - Writing Secure Code
Dependency Injection in Silverlight
Becoming A Presenter in the .NET World
Silverlight 2 with Visual Studio 2008 and Expression Blend
ASP.NET AJAX with Visual Studio 2008
Ad

Modern Web - MVP Testable WebForms

Editor's Notes

  • #56: Build out slide.. Before you click through: take a minute to have student “read” test and talk out what it’s doing.