Life, Teams, and Software Engineering

CasperJS Tests Hang Against .NET Application

If you’re having issues with your CasperJS tests hanging  against your .NET application  after a page navigation you probably need to turn off Visual Studio’s “Browser Link” feature. This is the helpful tool that automagically updates your page after you change your CSS, but unfortunately it causes Casper to hang. In the Visual Studio toolbar (usually next to the “Start in Browser” button) you can turn this off.

Disable Browser Link

With this disabled your CasperJS tests will be able to finish.

Using Mixpanel with EmberJS

In trying to add Mixpanel analytics to a project, I discovered that this is not so straightforward in client side MVC frameworks like EmberJS (we’re using v1.2 as of this writing).  There is a nice writeup here but it’s out of date from a Mixpanel perspective, as they discontinued Streams a few months ago.  The solution I arrived at involves a global jQuery event handler on hashchange combined with a call inside my Ember application initialization. Gist follows.

Hopefully the Ember team comes up with a better way to do this sort of thing, since the only other examples trigger before the actual document URL is updated.  See here for a bit of history.

Keeping Bootstrap 3 btn-group Buttons Selected

The Problem

For some reason the Bootstrap 3 btn-group class doesn’t keep buttons selected by default (at least in 3.0.2).  It’s strange that this behavior isn’t easily configurable since I don’t think my use case is uncommon, but oh well.  Here is a jsfiddle demonstrating the problem.

 

The Solution

Basically you need to use jQuery’s on function to attach a click listener to each button within a btn-group. In the even handler:

  1. apply the Bootstrap .active class
  2. remove the class from any of its siblings (assuming you want button selection to be mutually-exclusive).

Using MvcIntegrationTestFramework for ASP.NET MVC Functional Testing

Most other web frameworks, particularly modern MVC frameworks (e.g. Rails, TurboGears, etc.), have first class support for performing full stack functional testing sans browser.  These tests typically execute something like this:

  1. Drop functional testing database
  2. Populate functional testing database with seed data
  3. Start up web stack
  4. Execute tests that perform GET and POST calls to your site
  5. Check that something did or didn’t happen
  6. Tear down web stack
  7. Repeat

.NET however is severely lacking in this area, requiring developers to jump straight from unit testing to browser testing with poor support for anything in between.  Truthfully, “poor” support might be generous.

Thankfully, someone else has felt the pain and has worked to fill the gap.  You can find a very helpful framework for performing this type of testing in ASP.NET MVC applications on Github, MvcIntegrationTestFramework.  However, there are several things missing from this to make it as good a solution as it can be.  Specifically, I prefer that any “unit” tests I run in my solutions run against their own database.  This means updating the Web/App.config file, something MvcIntegrationTestFramework doesn’t support out of the box.  Thankfully I threw together this NUnit TestSetupFixture that performs steps 1-3 for me automagically (though step #3 is at the beginning of every Fixture).

Why Run Functional Tests?

Ever had all your unit tests and data tests pass only to discover that no pages will load because you forgot to update your dependency injection?  Well that’s one reason, but another is that while Selenium tests have their place they are notoriously slow and don’t always have access to the backend like your unit tests do.

Want to check that a user can’t access a page after you revoke a permission?  To do this in Selenium you have to login as an admin, navigate to the user’s permissions, remove it, log out, login as that new user, and then try to navigate to that page as that user.  And that’s only if you don’t care if they can access that page when they do have the permission.  To do this in tests running at the level of MvcIntegrationTestFramework you can just hit the database directly to give the user a permission, make the page request as the user to make sure they can access it, remove the permission, and then try to access it again.  It is much more straightforward, lends itself to data-driven automation, and your developers will be much more likely to build and run these kinds of tests.

Updating the Website’s Web.config File

Here is a Gist I put together that shows how I perform this process from my functional test assembly.  It’s ugly but it works.  The trick here is to modify the Web.config of the application under test while the harness is running, and then put it back to normal when it’s finished running (or something goes wrong).  Just don’t commit while the tests are still running or you’ll check in that change.  But I know you all wait for your tests to finish before committing.

HTML Agility Pack

Something I have found very helpful for digging into HTML responses in these tests is HTML Agility Pack (available on nuget).  It gives you the ability to verify page elements in a simple way.  Just don’t become too reliant on the HTML markup since your tests will become very fragile.  This is just a quick way to get in there and run some quick assertions against your pages.

Still Don’t Get It?

I’ve found these tests to be most useful for places where you want to test your full application stack but don’t want to resort to something like Selenium to accomplish it.  For situations like security/permissions testing this layer can be very powerful.  You can hit every controller action directly all while having direct access to the database to tweak the little bits that make it all work.

Enhanced by Zemanta

Mission Tracking for Agile Projects

Despite agile methods doing a great deal to bring technology teams closer to the consumers and businesses they’re supporting, I’ve found that it is easy to develop a disconnect between a Business person’s view of progress and an agile team’s view of progress.

Given the question “are we on track?” delivery teams tend to answer this on a shorter time horizon then the business tends to care about.  It’s obvious that you’ll be getting two weeks worth of work in two weeks, but what does that move us towards overall?  Will I be able to move to a new market?  Will I attract new customers?  Establish new partnerships?  That thought led me to pose this question.

We would be far better off answering these questions from the perspective of the business owner, which I think is better phrased like this.

Based on our stated business goals (hopefully outlined in a roadmap) how far are we (in terms of man days, story points, etc.) from each stage today?

Even saying something like “we believe we have 6 sprints left before reaching that milestone” could be an unhelpful answer.  It all depends on what that stakeholder is looking for in terms of visibility.  You should be prepared to answer questions like these at a moment’s notice:

  • Will we be able to make our current milestone given our current progress?  If not, what can be done?
  • Will we need more personnel given the scope of the next major milestone?  If so, how many?  When should they be brought on?
  • Are the dates for our next milestone realistic?  If not, what can be done?
Answer questions like these and you’ve gone a long way towards closing the gap between the Executive’s view of progress and the team’s view of progress.
Are there any other big questions you have found to be really impactful in helping to sync the Executive and delivery teams?  How does your team deal with this issue now?
Enhanced by Zemanta
« Older posts

Copyright © 2015 Life, Teams, and Software Engineering

Theme by Anders NorenUp ↑