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

Want to bypass Microsoft.Practices.EnterpriseLibrary.Logging in MOQ test
Can you implement TDD in Pega?
how to test fluent validations error message
Test class design in Test Driven Development
capybara / Observe html5/history route change
What's the benefits of TDD from project management point of view?
IdentityServer4 first acceptance test
Testing an extension to expect.js
How to re-use asserts and/or setup in xBehave tests?
How to exclude null value when using FsCheck Property attribute?
Best technique/workaround for mocking assignment of private field?
Testing behavior not consistent when watching actor for termination
Innovative Software Engineering Methodologies [closed]
AssertJ and Mockito: check a slightly complex JTable event?
Have any of you applied TDD in VHDL?
cpputest - output more information about test case

Categories

HOME
ibm-bluemix
google-chrome-extension
proxy
amazon-ec2
plone
hp-exstream
raspberry-pi
webstorm
mean-stack
q
jxls
directx
bs4
pheatmap
add
basic
session-variables
python-unittest
ssl-client-authentication
rascal
usergrid
size
decimal
after-effects
reactive-cocoa
flux
google-cloud-speech
ehcache
csrf-protection
css-animations
mustache.php
telerik-reporting
cultureinfo
trading
smb
pepper
underflow
tooltipster
filezilla
social-media
maquette
jspm
bluestacks
iframe-resizer
semantic-versioning
catch-all
hybridauth
android-nestedscrollview
catalog
fusionpbx
unspecified
fedex
sql-server-agent
password-encryption
no-www
s
menuitem
youcompleteme
qsslsocket
python-webbrowser
svmlight
statsd
nativeapplication
qtwebview
pillow
redundancy
wdf
httplistener
rotativa
android-textview
elements
dstu2-fhir
fody
mathematica-frontend
jwplayer7
captivenetwork
goose
system.management
execute
lib.web.mvc
intellij-14
generic-programming
winddk
relocation
id3v2
wp-query
yorick
message-driven-bean
prettify
quantlib-swig
xsockets.net
ruby-datamapper
opcache
jplaton
spring-validator
pygit2
hamiltonian-cycle
coderush
ohm
gwt-ext
cinema-4d
gdlib
floating
.nettiers
dmx512
javap
zend-decorators
dbisam

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App