18. October 2013

Bootstrapping Quality

I gave a talk to CompSci seniors at Seattle University today about Version Control Systems, Test-Driven Development and Continuous Integration. Here are the slides:

During the presentation I tried to demonstrate TDD by building FizzBuzz in a test-driven manner, then showed off Dependency Injection and Mocking by adding text from my twitter feed.

Download the source here.

Notes:

  1. I removed my twitter app authentication keys, so if you execute the program it won’t work. See the file Twit.cs and Twitter Development if you feel the need to resuscitate this.
  2. I turned off the Azure VM that hosted the Jenkins instance referenced in the slides. It was costing me two cents an hour! That’s like a latte every week.

Comments

14. October 2013

Lovely "usage" wrapper for jasmine data-driven tests

I was looking for a way to do a bit of data-driven testing with jasmine, and JP nailed it.

describe("username validation", function() {
  using("valid values", 
    ["abc", "longusername", "john_doe"], 
    function(value){
      it("should return true for valid usernames", function() {
        expect(validateUserName(value)).toBeTruthy();
      });
    });
});

The gist is that you can simply wrap your it() calls in a function that iterates over an array and pass the data in with each loop. It works great with synchronous and asynchronous tests. The function integrates cleanly with the test runner so each spec gets its own descriptive row. Best of all, it has a very pleasing syntax that makes it clear what is going to happen when you use it.

Check out JP’s blog for the source.

Comments

10. October 2013

The Worst API ever

I’m integrating with what may be the worst API ever. Check this out!

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
  <Create xmlns="http://www.REDACTED.com/api/">
   <data>
    ["{\"type\":\"REDACTED\",\"data\":\"{ParentType: 'REDACTED', ParentId: '1', ActionEntityType: '2', ActionEntityId: '3', SegmentId: '0' }\",\"normalize\":false}"]
   </data>
  </Create>
 </soap:Body>
</soap:Envelope>

So much wrong in so little space. Here we have:

  • a SOAP message…
  • … with a “data” parameter…
  • … containing a JSON array…
  • … of a single string
  • … of JSON (string-escaped, of course)…
  • … that itself contains “data” parameter…
  • … which is again a string….
  • … of improperly formatted JSON!

I suspect the last improper formatting is to reduce the amount of quote-escaping needed given that you are now in double-escape territory. Oh, and lest you think it’s just being permissive — if you attempt to properly JSON-encode the inner data parameter, the call fails with “unable to parse JSON!”

This. Is. A. Maz. Ing.

Comments