Monday, December 10, 2012

Formatting Options for Dart Tests

‹prev | My Chain | next›

I would dearly love to be able to run my client-side Dart test without a browser. Sadly, this still seems an impossibility, so tonight I reexamine the possibilities available when running them manually.

Last night I was able to run a sanity check test in the console. I see in the SDK that there is an html_config.dart for the unittest library. So I pull that into my test:
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';

import '../public/scripts/Views.AddComicForm.dart';

main() {
  useHtmlConfiguration();

  test('Sanity check', (){
    Expect.equals(1+1, 2);
  });

}
After pulling the library into my test, I make use of the useHtmlConfiguration() method to convert my Dart console test to something that displays its results in the main browser window:


There also an enhanced version of the HTML test runner. Mostly this involves adding the word "enhanced" to the library and the class name. It also helps to group my one test, which results in a simple test that looks as follows:
import 'package:unittest/unittest.dart';
import 'package:unittest/html_enhanced_config.dart';

import '../public/scripts/Views.AddComicForm.dart';

main() {
  useHtmlEnhancedConfiguration();

  group('simple group', () {
    test('sanity check', (){
      Expect.equals(1+1, 2);
    });
  });
}
That results in the slightly more appealing:


It's no headless testing, but it's nice.

The main impetus for playing with these testing tools is to decide how much of the testing chapter in Dart for Hipsters needs updating. So my next step is to covert the HipsterCollectionTest.dart that I have lying about into this new format. Amazingly, 3 of the 6 tests from earlier this year still pass:


Happily, getting those tests to pass involves only updating the testing code for Dart M1 release. I do not need to make changes to the tests themselves. It seems that I may need fewer changes to the testing chapter than anticipated, which is always nice.

That said, I am using the currently deprecated asyncTest test for many of my tests. I will pick back up tomorrow trying to figure out the new Dart way for testing these things.

Day #595

No comments:

Post a Comment