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
4
votes
2 answers

Dart - unit test of a stream event timing out

This is a very simplified version of the problem I have encountered when trying to unit tests streams. The test checks that the correct event has been added to the stream - it appears to work fine - for example, change the value add( 'test') to add(…
richard
  • 2,887
  • 5
  • 26
  • 36
3
votes
1 answer

How to make ViewChild work in a unit test

I have a test like @Component( selector: 'my-test', template: 'none', changeDetection: ChangeDetectionStrategy.OnPush, ) class MyTestComponent { final AngularClientCache clientCache; MyTestComponent(this.clientCache) { …
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
3
votes
2 answers

How to debug browser tests with the new test package

browser tests need to be run from command line like pub run test -pdartium. Is there a way to debug such tests.
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
3
votes
1 answer

How to test a method using a Future in Dart?

I would like to test a method which execute a POST on another server : Future executePost() { _client.post("http://localhost/path", body : '${data}').then((response) { _logger.info("Response status : ${response.statusCode}"); …
matth3o
  • 3,229
  • 3
  • 20
  • 24
3
votes
2 answers

Dart - mocking the Element class

I am trying to create a unit test that requires me to mock the Element class So my code looks something like import 'dart:html'; import 'package:unittest/unittest.dart'; import 'package:mock/mock.dart'; @proxy class MockElement extends Mock…
richard
  • 2,887
  • 5
  • 26
  • 36
3
votes
1 answer

Better way of defining a "accept" and "notAccept" matcher for unittest

I want to define matchers to check if a parser can accept a string or not. I did it but not feeling good. Dart unittest code: library test_parser; import 'package:unittest/unittest.dart'; import '../lib/shark_parser.dart'; main() { SharkParser…
Freewind
  • 193,756
  • 157
  • 432
  • 708
3
votes
2 answers

Warning when mocking a class

I am reading this article - https://www.dartlang.org/articles/mocking-with-dart/ - about mocking wiht Dart and have gotten this simple example working. import 'package:unittest/mock.dart'; class Foo { int x; bar() => 'bar'; baz() =>…
3
votes
1 answer

Headless testing using content_shell --dump-render-tree

I'm trying this Gist on my Kubuntu dart development box with one of my projects(standard unittest htmlconfiguration), I'm not seeing the Browser Output bit for the tests, rather I'm getting this Content-Type: text/plain layer at (0,0) size…
user2685314
  • 1,059
  • 6
  • 9
2
votes
2 answers

Flutter unit testing - Binding has not yet been initialized

Used SharedPreference throwing error in Unit test. In one function I have used SharedPreference and during it's unit testing getting error as "Binding has not yet been initialized" and many other errors too. Working unit test: After uncommenting…
Anand Suthar
  • 3,678
  • 2
  • 30
  • 52
2
votes
2 answers

Dart - How do you write a test against a function that calls exit()?

I want to test a function that calls exit. Basicly, I have a console application, that asks the user if he is sure that he wants a directory to be overwritten. When the users answers "No", the directory won't be overwritten, and the program should…
Kasper
  • 12,594
  • 12
  • 41
  • 63
2
votes
2 answers

Dart Unit Test - Always passing

All, Here is a unit test for checking the size of a collection main() { test("Resource Manager Image Load", () { ResourceManager rm = new ResourceManager(); int WRONG_SIZE = 1000000; …
NullPumpkinException
  • 1,396
  • 1
  • 18
  • 22
2
votes
1 answer

Access the DOM in Dart unit tests

I am trying to write a test for the Pirate Badge tutorial thats meant to get people started using Dart. I have the following directory structure: The code in 6-piratebadge is an untouched version of what comes in the tutorial. What I have added is…
Mike Hogan
  • 9,933
  • 9
  • 41
  • 71
2
votes
1 answer

Dart Mocking a Function

How do I test that a mocked function was called? I found this example on Mocking with Dart - How to test that a function passed as a parameter was called? and tried to extend it to check if the function was called. library test2; import…
richard
  • 2,887
  • 5
  • 26
  • 36
2
votes
2 answers

Refactor friendly mocking in dart

So far all the mocking libraries I've seen in dart (unittest/mock, dartmocks) use strings to represent the method calls. e.g. foo.when(callsTo('fum')).thenReturn(...); problem is when I want to rename fum then the IDE won't pick up my mocked method…
Anders
  • 1,337
  • 1
  • 8
  • 17
2
votes
1 answer

Unit Testing Http status code

How can I write a unit test to return the status code of a response that is part of a Future? I got this far before getting stuck import 'package:http/http.dart' as http; test( "test future", (){ Future future = http.get(…
richard
  • 2,887
  • 5
  • 26
  • 36