5 comments on “Naming Unit Tests

  1. I’ve been wondering how you would do something like this with Java unit testing. When using Jasmine, a JavaScript BDD unit testing framework, you use a string to describe what the test is, and then you pass in an anonymous function to actually run the test:

    
    describe("Method Name tests", function() {
      var a;
    
      it("should totally do what I want it to", function() {
        a = true;
        expect(a).toBe(true);
      });
    
      it("should STILL totally do what I want it to", function() {
        a = false;
        expect(a).toBe(false);
      });
    });
    

    describe is used to set up a “suite” of tests, which are usually for a particular feature or a single method that you’re testing. it just sets up an individual test. I like this approach because you don’t have to write out a long camel-cased description of the test: you just write it as a sentence and you don’t have to bother with a method name. Also, with JavaScript’s closures, you can share data between the tests rather simply (like the a variable in the example, though it was mostly pointless to share that one).

    Like

  2. Pingback: Testing Interface Invariants | Programming Ideas With Jake

Leave a comment