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
2
votes
1 answer

How does protectAsyncN work in Dart unittest package?

I really don't understand the purpose of protectAsyncN methods. Could someone please explain me how should it work? For example, imagine following test case: import "package:unittest/unittest.dart"; import "dart:async"; void main() { …
Samuel Hapak
  • 6,950
  • 3
  • 35
  • 58
1
vote
1 answer

What is the difference between `true` and `isTrue` or `false` and `isFalse` in dart test?

I already know using the isTrue and isFalse matchers can make test assertions more descriptive and easier to read. However, I want to know if there are any other benefits or reasons for using them instead of boolean values. expect(actual,…
Hamed
  • 5,867
  • 4
  • 32
  • 56
1
vote
1 answer

How to unit test a stream that is returned from a function?

I have the below setup: class Resource { T? data; String? error; Resource._({this.data, this.error}); factory Resource.success(T? data) => Resource._(data: data); factory Resource.error(String error) => Resource._(error: error); …
Mena
  • 3,019
  • 1
  • 25
  • 54
1
vote
0 answers

Flutter Stubbing : use Stub method's return value property

Hi this is the method i want to stub : the checkLimit method. class MyClass { final ResponseBase isAvailable = await sampleRepository.checkLimit(data: _data); if (isAvailable.status == ResponseStatus.notOk) { yield…
1
vote
1 answer

Two different setUp methods for the same tests

I currently have two groups of tests that are identical in every way except the setUp() method call. I want to simplify the code so that the set of tests is only defined once but each group runs its own setUp() method and then the identical set of…
jxmorris12
  • 1,262
  • 4
  • 15
  • 27
1
vote
1 answer

Is there a regex matcher in the test package

I have an element like and I want to check if the style attribute contains width: xx%; with a regex like r'width: \d{1,3}%;' await bar.attributes['style'] returns…
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
1
vote
1 answer

WebStorm DartUnit with test api, run/debug error

I'm using WebStorm IDE and test api which is named unittest before. The test works fine using the command: pub run test:test test/sample.dart /test/sample.dart library testproject.sample; import 'package:test/test.dart'; void main() { …
Miguel Fermin
  • 380
  • 1
  • 3
  • 13
1
vote
1 answer

The built-in library 'dart:html' is not available on the stand-alone VM

I'd like to be able to unit test my custom polymer elements. Given a component in lib/web_components: class Foo extends PolymerElement { Foo.created() : super.created(); } and a test in test/web_components: main() { test("Should Be a…
Stephen__T
  • 2,004
  • 3
  • 25
  • 48
1
vote
1 answer

How can I make test inside a then statement in Dart

I want to do some unit tests on some functions, but I need to execute all the tests after the completion of a Future. To develop my problem, Here an example of what I want to do : registerToServer(contentOfRequest).then((id){ test('test…
1
vote
0 answers

angular component test for events

I have a custom component and try to test for the emitted events My component looks like this: @Component( selector: "my-component", templateUrl: 'component/my-component.html', useShadowDom: false, publishAs: "ctrl" ) class MyComponent…
Slemgrim
  • 937
  • 2
  • 8
  • 23
1
vote
0 answers

Why doesn't solo_group call it's setUp method

I'm using scheduled_test to test my Polymer Dart elements. This works fine, until I try using solo_group(). My tests depend on the setUp() method being called, but when solo_group() is used, the setUp() method is not called. My tests,…
James Hurford
  • 2,018
  • 19
  • 40
1
vote
1 answer

Write unittest and save in the separate folder

I am trying to write a unittest for my class. First of all, i install the package unittest and create a spec folder to save all my unittest files. Then i create a test dart file with following contents: library i18n_test; import…
softshipper
  • 32,463
  • 51
  • 192
  • 400
1
vote
0 answers

Dart How to unit test a simple function

I love the way that you can write clean concise code in Dart, but it appears that Dart is one of those languages that it easy to write but hard to test! For example, given the following fairly simple method, how does one go about unit testing…
richard
  • 2,887
  • 5
  • 26
  • 36
1
vote
1 answer

Mocking with Dart

I've been trying to get my head around the mocking library in dart, but it seems I've still not got it. In my library, I have an HTTP request to an external resource, which I would like to mock as to not rely on the external resource all the…
Marcos Placona
  • 21,468
  • 11
  • 68
  • 93
1
vote
2 answers

how to unit test heavily asynchronous processes in dart?

I have a library which has many async parts to it, and testing a specific part of it can sometimes mean waiting for n asynchronous processes to complete before the test is available to actually be run. I have been using this method to achieve my…
Daniel Robinson
  • 13,806
  • 18
  • 64
  • 112