Skip to main content

New site for Dart news and articles

For the latest Dart news, visit our new blog at .

Use the new Dart unit test library

Posted by Seth Ladd

Today we published Unit Testing with Dart, a new article and tutorial on writing tests in Dart. The Dart SDK now ships with the unit test library, so it's a good time to start testing (pun intended) this new library with your code.

The Dart unit test library takes inspiration from Hamcrest and dart-matcher. It supports both single and grouped tests, synchronous and asynchronous tests, and has a suite of matchers.

Here's an example simple test:

  test('QuickSort', () =>
    expect(QuickSort([5, 4, 3, 2, 1]),
      orderedEquals([1, 2, 3, 4, 5]))
Here's how you group tests:

group('My test group', () {
  test('Test 1', () => expect(0, equals(1));
  test('Test 2', () => expect(1, equals(0));
Start using unit tests with your Dart code today. As always, please join the Dart mailing list to chat with the team. And thanks for trying Dart!