tdd


TDD - How to write test case for a method that as Assembly.LoadFrom(…)


I have got method which is using Assembly.LoadFrom(...) statement and returns the supported cultures from that satellite assembly, so how could I write unit tests for that type of methods.
What I did was, wrapped that static method/logic to return cultures in anther class and used it's instance method. Is this the right approach?
Is this the situation?
aMethod(whatToLoad) {
// other stuff
x = Assembly.LoadFrom( whatToLoad );
// code using x
}
First principle: We are focusing on testing aMethod(), the testing of Assembly.LoadFrom() is a separate problem. While we are building tests for aMethod() we don't try to test its dependencies.
So here what kind of tests might we need?
That we pass the right value for whatToLoad
That we correctly store/use the value returned
That we correctly handle errors or exceptions thrown from Assembly.LoadFrom()
It is easiest to do this if the test can supply a Mock implementation. Then we can test 1 by checking that the Mock received the expected value. Test 2 by returning a well defined value (or for mulitiple tests different interesting values) Test 3 by generating chosen error conditions.
So you have changed your code to something like this:
aMethod(loader, whatToLoad) {
// other code
x = loader.Load( whatToLoad );
// code using x
}
Maybe the loaded is injected in some other way, but the point is that you can now specify different tests my setting up a suitable loaoder. For example, for the first test.
testLoader = new MockLoaderThatRembers();
tested.aMethod(testLoader, loadThis);
assertEquals(testLoader.getLoader(), loadThis);
So if that's the kind of thing you are doing then yes, I'd say you're enabling TDD.

Related Links

How to deal with those TDD breaking people? [closed]
How to create a mock object based on an interface and set a read-only property?
Exercises to enforce good practices such as TDD and Mocking
What are some reasons why a sole developer should use TDD?
Database integration tests
Pseudocode Programming Process vs. Test Driven Development
Can TDD Work in a Architect/Implementer Environment? [closed]
Adversarial/Naive Pairing with TDD: How effective is it?
Single most important thing to impart when teaching TDD [closed]
What happened to NUnit?
Developers are dissatisfied with TDD. Is TDD really the problem, or is it a lack of skill of novice practicitioners?
Application Testing
How to shift your paradigm to test-driven development
How do I tell MSTEST to run all test projects in a Solution?
Research on TDD
Why are TDD 'Spikes' called 'Spikes?

Categories

HOME
twitter
arduino-uno
winforms
image
omnet++
raspberry-pi
gis
amortized-analysis
rubygems
frameworks
node-notifier
medical
iggrid
dacpac
floating-action-button
decomposition
fatal-error
solaris-10
oracle-coherence
contextmenu
nodatime
scriptcs
tdd
sparse-matrix
apache-commons-io
kannel
tooltipster
windowbuilder
madlib
lightswitch-2013
bcd
siesta-swift
framemaker
protovis
picasso
avro4s
fakeiteasy
midl
mime
auto-update
jquery-validate
worksheet
boost-multi-index
winscp-net
windows-mobile-6.5
sqldf
chord-diagram
or-tools
gnome-shell-extensions
android-fonts
angular-cache
infix-notation
measures
persist
ipconfig
metaclass
django-unittest
dukescript
codeigniter-url
tt-news
network-interface
angularjs-ng-click
rdl
zend-route
dealloc
rtmfp
cloud-connect
typo3-neos
page-layout
dbconnection
ora-00911
hungarian-algorithm
pushbackinputstream
eventlistener
selected
itmstransporter
hosts-file
gnustep
gcj
oncheckedchanged
gamequery
bespin
meego
adrotator
pascal-fc
thread-local-storage
zune

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App