Dave's Notebook

CSS Animation Resources

This week I discovered CSS Animations.  Well, I shouldn’t say I discovered it so much as I finally spent some time figuring out what it is and why I would care about it.  This could make so much of what we normally do in JavaScript entirely unnecessary.  So, more for my own benefit than anything else, I thought today I would just create a list of resources that are available. But first, why would you want to use CSS for animation when JavaScript could do it just as well?

Read More

NUnit, Unity Dependency Injection, MOQ and Private Fields

I had an interesting puzzle to solve this week that I thought I would share with you in case someone else is looking for a similar solution. There was some code that I needed to test that ultimately called into the database. Since this is a UNIT test and all I was interested in testing was one specific function and the state of one specific field in another  object, I had neither the need, nor the desire, to let that call to the database happen.  Since MOQ is  my mocking framework of choice, I wanted to mock out the database object the method was using so that it would return whatever was expected without actually calling down into the database. There were several problems.  The first was that the database object is a private field in the class I was testing and it got created by the constructor.  Second, the code that needed to use the database object is passing the object by reference (using the “ref” keyword) so that I could no setup my class that needed that object to just ignore it. There were some other items I needed to inject, but they were pretty straight forward.

Read More

Technical Debt Is Inevitable

Whoa there Dave.  What are you talking about?  Have you given up the fight? You who have preached the TDD religion.  You who’ve struggled to get organizations to adopt naming conventions, to use version control systems and to use project management software.  The same guy who has implemented continuous integration on his current project?  What’s this world coming to?

Read More

Is Your Architecture Crippling Your Unit Testing?

Last week I wrote a post that talked about Unit Testing and the need to make sure you are only testing one particular unit of code at a time.  The post was well received.  But I am surprised that no one commented on the glaring hole I left in the post.

In that post, I said:

So, one way you might go about separating your code from the data is by using dependency injection.  What I’m talking about here is simple injection.  No frameworks.

So, let’s say you have a class you may have called user role.  Given a user id, it will return a role.  How could we code this so that it doesn’t matter where the code comes from?

By declaring an interface to a user role object maybe and then passing an object of that type to the constructor.

By doing this, you can use a fake object when you are testing and a real object when you are using the system in production, but your code won’t really care which one is being used.

At some point we will need to retrieve data.  But the data is always just a side effect.  If you have a way of getting at the data, and you are confident it works, because that standard mechanism has been tested, then you don’t need to write test for the data access piece, you only need to write test for “given I have good data, this method will do this.”

As I reflected on the post, I realized that this may make sense to you if you are already implementing this in your code.  But, if you are new to dependency injection and the concepts of loose coupling in general, this might be a foreign concept for you.

At the very least, I realize now that it could be flushed out a bit more.

So, here we go.

Read More

Running Selenium In Parallel With Any .NET Unit Testing Tool

Running Selenium in parallel from .NET seems to be a problem because, as of the time of this writing, I’ve yet to find a viable way of running selenium test on multiple browsers using Selenium Grid.  This doesn’t mean that there aren’t a few articles out there that have some kind of solution.  But they’ve never satisfied me as something that I could easily plug into my already created test. While my preferred testing tools are NUnit and SpecFlow, the method I am about to propose should work with any existing test harness you might want to use.  The only prerequisite is that you are using Page Models to wrap your access to any particular web page. This article assumes that you already:

  • know how to write Selenium tests
  • know how to use Selenium Grid
  • know how to use the Page Model pattern
  • know how to use your chosen test harness.

Read More