How should I test a Future in Dart?

Full example of how to test with the completion matcher is as follows. import ‘package:unittest/unittest.dart’; class Compute { Future<Map> sumIt(List<int> data) { Completer completer = new Completer(); int sum = 0; data.forEach((i) => sum += i); completer.complete({“value” : sum}); return completer.future; } } void main() { test(“testing a future”, () { Compute compute = new … Read more

When using kotlin coroutines, how do I unit test a function that calls a suspend function?

Fixing async As implemented, your someFun() will just “fire and forget” the async result. As a result, runBlocking does not make a difference in that test. If possible, make someFun() return async‘s Deferred and then, in runBlocking, call await on it. fun someFun(): Deferred<Unit> { // … Some synchronous code return async { suspendFun() } … Read more

CoffeeScript unit testing?

You can use any javascript testing framework with CoffeeScript. This will be testing the Javascript that CoffeeScript outputs which is necessary since CoffeeScript itself can’t be executed. Writing your own testing framework for CoffeeScript is fun (I did) but entirely uneccessary. UPDATE: Jasmine tests can be run on node.js in which case both the tests … Read more

what does >> and 1* means in this groovy statement?

This is not groovy per se, but the testing framework called Spock (which is very popular among Groovy developers, for good reasons 🙂 – http://spockframework.github.io/spock/docs/1.0/index.html This expression in particular is a way to instruct Spock that it should expect exactly one call to the method prova in myService, and that this call should be mocked … Read more

Angular 2: How to mock ChangeDetectorRef while unit testing

Update 2020: I wrote this originally in May 2017, it’s a solution that worked great at the time and still works. We can’t configure the injection of a changeDetectorRef mock through the test bed, so this is what I am doing these days: it(‘detects changes’, () => { // This is a unique instance here, … Read more