Coding Naked – Practical steps to moving towards & embracing TDD. We'll overview the normal roadblocks that people typically run in to, and practical ways to overcome those road blocks on your way to embracing Test Driven Development - make coding without tests as uncomfortable as coding naked!
Code: https://github.com/calebjenkins/Acme.CodingNaked
Presenting at events: https://developingux.com/tag/coding-naked/
15. Test Framework Test Runner
Code Tests
15
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
21. Visual Studio
(VS Test Adapters: xUnit ,nUnit, VS Test etc)
> dotnet test (cli)
Continuous Integration (Team City)
Continuous Integration (GitHub Actions)
Test Runners
23. 3 A’s
23
– Set up the scenario and the initial input values.
Often in a common [TestFixtureSetup] or [Setup] method
- Action that creates the outcome that is being tests,
usually calling some method in your code to test the result.
– Is a boolean statement to your testing framework to
declare the expected outcome.
Results in Pass or Fail
Arrange Act Assert
Test Code
24. 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
28. Test Runner
return values
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
Simple Tests
41. 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
42. Data Access
Data Logic
Integration Service Proxy
App Domain Domain Validation
UI Logic
UI
How do you test this
with these
dependencies
Harder to Test
44. 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
45. 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
48. - 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!”
60. UI Data
Data
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
61. Edges are all around us
Data
UI
Network
Disk
IO
other
67. These examples are for the expressed purpose of
demonstrating unit testing scenarios.. none of this code
(especially the supporting non-testing code) is
intended to be deployed in production scenarios. This
is just some code from a talk at some conference.
There's no warranty, express or implied. Works on my
machines. I don't know you and I don't know how you
got here. Stop calling. Caleb Who?! 👀