Quark

Build Status Coverage Status


Abstract

Quark is a comprehensive testing framework, covering different styles and types of tests. Reflection with Reflectable makes test doubles, grouping and test definition a breeze.

Usage

Unit Testing

// greeter.dart

class Greeter {
  final Greeting greeting;

  Greeter(this.greeting);

  String greet(String name) {
    return '${greeting.phrase}, $name!';
  }
}

// An example of a collaborator that can be mocked
class Greeting {
  final String phrase;

  const Greeting(this.phrase);
}
// greeter_test.dart
import 'package:quark/quark.dart';
import 'greeter.dart';
export 'package:quark/init.dart';

class GreeterTest extends UnitTest {
  @test itGreetsAPerson(GreetingDouble greeting) {
    // Creation using injected test double
    final greeter = new Greeter(greeting);

    // The greeting will return "Yo"
    when(greeting.phrase).thenReturn('Yo');

    // Make the assertion
    expect(greeter.greet('buddy'), 'Yo, buddy!');

    // Verify that the phrase was fetched from the greeting.
    verify(greeting.phrase).wasCalled();
  }
}

// Clean test double declaration inspired by Mockito
class GreetingDouble extends TestDouble implements Greeting {}

Integration Testing with Gherkin Features!

Feature: Welcome message on the home screen

Scenario: Not logged in
  Given I'm not logged in
  When I visit the home page
  Then I expect to see "Hello, Guest!"
import 'package:quark/quark.dart';
export 'package:quark/init.dart';

class WelcomeMessageOnTheHomeScreenTest extends IntegrationTest {
  @Given("I'm not logged in")
  imNotLoggedIn() {}

  @When("I visit the home page")
  iVisitTheHomePage() {}

  @Then("I expect to see \"(.*?)\"")
  iExpectToSee(String message) {}
}

Running tests

Quark works on all platforms. Here's how to run all the tests:

> git clone https://github.com/emilniklas/quark.git
> cd quark
> pub serve # Start the transformer server - for Reflectable

# Then, in another tab
> pt -p vm,dartium,content-shell && pt -p chrome,phantomjs,firefox,safari --pub-serve=8080

Libraries

quark
quark.browser
quark.init
quark.integration
quark.test_double
quark.unit
quark.vm