Questions tagged [dart-unittest]

A library for writing dart unit tests.

Dart includes a unit test library that is easy to use, adaptable, and supports both synchronous and asynchronous tests.

More information:

53 questions
43
votes
4 answers

How to test a private function, in Dart?

Say I defined a private function in a dart file hello.dart: _hello() { return "world"; } I want to test it in another file mytest.dart: library mytest; import 'dart:unittest/unittest.dart'; main() { test('test private functions', () { …
Freewind
  • 193,756
  • 157
  • 432
  • 708
35
votes
1 answer

Dart - How run a function after or before each test?

I'm using the Dart test package: https://pub.dartlang.org/packages/test Often, I want to run some function before or after each tests in my test file. Does the test package provide something for this?
Kasper
  • 12,594
  • 12
  • 41
  • 63
20
votes
7 answers

How to test an exception from a future

Continuing from yesterday question, how would I test that a async method throws an exception. main(){ test( "test2", () async { expect( await throws(), throwsException); }); } Future throws () async { throw new…
richard
  • 2,887
  • 5
  • 26
  • 36
15
votes
2 answers

How to wait for an asynchronous setup in a unit test, in Dart?

My unit tests require a setup that needs to run asynchronously. That is, I need to wait for the setup to finish before the tests are run, but the setup deals with Futures.
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
12
votes
3 answers

How can make a matcher for a string containing a substring, while ignoring case

I'm writing a unit test using mockito to mock a dependency and check we're calling it with the right argument. We should be passing in a string, so I'm trying to match on that function argument, but without asserting on the whole string, in case we…
Jezzamon
  • 1,453
  • 1
  • 15
  • 27
12
votes
4 answers

Dart - how to mock a method that returns a future

I have a class that defines a method that returns a Future. The Future contains a list of class that also return a future. class User{ Future> albums(){ }; } class Album{ Future> photos(){ …
richard
  • 2,887
  • 5
  • 26
  • 36
9
votes
2 answers

How to set the timeout of test in dart's unittest?

Is it possible to set the max time that a test can run? Just like: @Test(timeout=1000) public void testSomething() {} in jUnit?
Freewind
  • 193,756
  • 157
  • 432
  • 708
8
votes
2 answers

Is there a way to get a test coverage report for unit testing in Dart Language?

Is there a way to get any type of a test or code coverage report (text or graphical) of the unit testing of your Dart code?
corgrath
  • 11,673
  • 15
  • 68
  • 99
7
votes
2 answers

Writing a unit test for asynchronous code in Dart Test

After reading the Unit Testing with Dart somehow I'm still can not understand how to use it with Futures. For example: void main() { group('database group', () { setUp(() { // Setup }); tearDown(() { // TearDown }); …
Alex F
  • 3,180
  • 2
  • 28
  • 40
6
votes
1 answer

Dart Event Queue: How to debug event queue?

I'm writing some integration tests which utilize an HttpServer, a bunch of Directory().watch()'ers and possibly some other future/stream listening code. I'm using the following test configuration: class LaserServerTestConfiguration extends…
Lex Berezhny
  • 512
  • 3
  • 15
6
votes
4 answers

Mocking HTTP response with Dart

I have been working on a new API wrapper and don't want to be calling the API every time my unit tests run. So as described here, I'm mocking it. I initially thought there was something wrong with the way I'm mocking it, but it seems the problem is…
Marcos Placona
  • 21,468
  • 11
  • 68
  • 93
5
votes
1 answer

How to mock server response - client on server side

I'm trying dart and I'm writing a client on the server side : new HttpClient().post(InternetAddress.LOOPBACK_IP_V4.host, 7474, '/path').then((HttpClientRequest request) { request.headers.contentType =…
matth3o
  • 3,229
  • 3
  • 20
  • 24
5
votes
2 answers

Dart How to mock a procedure

How do I go about mocking a procedure (as apposed to a function see here) For example, given the following typedef and procedure, typedef int Adder(int a, int b); int useAdder(Adder adder) { return adder(1, 2); } How could you write a mock…
richard
  • 2,887
  • 5
  • 26
  • 36
5
votes
1 answer

Read a data file for unit test in Dart

I'm using this snippet to read a data file in a unit test: var file = new File('/Users/chambery/projects/Foo/src/resources/skills.yaml'); Future finishedReading = file.readAsString(); finishedReading.then((text) { print(text); …
Todd Chambery
  • 3,195
  • 4
  • 19
  • 27
4
votes
1 answer

Failed to load dartium when running test

I'm running dart test using test library. pub run test -p dartium When this command is executed I'm getting below error, I have dartium and dart sdk downloaded and in system path. Failed to start Dartium: No such file or directory Command:…
ashokd
  • 393
  • 2
  • 11
1
2 3 4