I have not view on the explicit scopes either way
really, other than it seems to add a lot of extra code
for seemingly no benefit.
I believe that OnApplyTemplate should be part of Arrange
(version B) as that makes more sense to me.
Ugh, that looks very ugly
I think I'd prefer B given the functionality of
OnApplyTemplate. The explicit AAA syntax I'm not sure
of, I think a simple "// Arrange" comment suffices.
Initial point: rename ctl to customControl or something
else that makes more sense than "ctl". Grab a copy of
Robert Martin's "Clean code" for a dozen reasons why :)
Your test wants to check whether the invocation was
called, thus anything prior to core.FireEvent( ) is
preparation, thus should be in the scope of Arrange.
Hmm, I like this explicit AAA-style.
Difficult to say what version is better. I think version
B makes a little bit more sense because the
OnApplyTemplate is part of the setup of the environment.
-
Mark Monster
Seems like the using scopes are some form of recording
mechanism?
Anyways, my vote goes to B since it feels more of an
arrange operation.
1. With all my respect to IDisposable this syntax looks
like overkill. Why would you need
using(SilverUnit.Assert)? What kind of clean-up will it
trigger?
2. Judging from the name of the test, I'd put
OnApplyTemplate in "arrange" section.
I think a little whitespace between the AAA sections
does the job just fine. Unnecessary code, and even
comments, seem like overkill.
Even better, with the context-specification style, you
move the arrange and act into you setup code and get an
even clearer look at your assertions.
I would pick B as it does seem to belong to the arrange
scope and is better grouped with the other control
template code.
Was this code just for to demo this kind of thing or is
this from "real" code?
I think unit testing is very useful but I don't think
it's nessessary to test that a mouse click changes the
mouse state to pressed, that's kind of a given and means
you wrote all the extra test code for nothing. Maybe I'm
missing something though.
I would personally test the behaviour of what is to
happen when the mouse is pressed, e.g save details or,
fire weapon etc.
I'm with the majority in that the using statements are a
bit overkill, considering comments are already available
to provide visual queues. So unless they do more than
that, I would vote no.
And isn't this just the kind of thing you railed against
in your critique of the ASP.NET MVC unit tests? :)
I have no opinion on the usings as I haven't done any
Silverlight unit testing.
However, I usually put the Arrange-Act part in my Setup
method, and keep all Asserts in my tests methods. I feel
no need to mark my sections as one or the other.
Option B fits that pattern.
Another benefit from arranging tests this way, is that
we can name our fixture after the user story or use case
scenario, and the tests after each desired outcome.
The explicit organization of the code is appealing on
one level especially when someone is not a seasoned user
of a testing framework or when tests aren't working as
expected. But, I'm also with the majority that the using
statements may be too much.
I like version B because I view "assert" as a single,
specific action and the OnApplyTemplate method feels
like setup [arrange] to me.
too much typing, aren't why trying to minimize code?
1 vote for Version B
using statements would need to provide additional
functionality otherwise comments would win
If A was correct, you're gathering two tests into one.
=> B