Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Adds package:litetest, uses it instead of package:test under testing/dart #26215

Merged
merged 1 commit into from
May 20, 2021

Conversation

zanderso
Copy link
Member

@zanderso zanderso commented May 18, 2021

Towards flutter/flutter#82134.

This PR adds a Dart testing library under testing/litetest. It is essentially a wrapper around package:async_helper from the Dart SDK source repo at //pkg/async_helper with modifications to make it work in the environment of flutter_tester. This wrapper is needed to ensure that all tests run to completion before the process exits. This is accomplished by opening a ReceivePort for each test, which is only closed when the test finishes running.

The API of package:litetest is pretty close to the parts of package:test used by the tests under testing/dart with some small differences requiring patch-ups that are included in this PR.

@zanderso zanderso added the Work in progress (WIP) Not ready (yet) for review! label May 18, 2021
@google-cla google-cla bot added the cla: yes label May 18, 2021
@zanderso zanderso marked this pull request as draft May 18, 2021 06:27
@zanderso zanderso force-pushed the dart-test-rm-test branch 3 times, most recently from ab5238c to abd7b11 Compare May 19, 2021 05:26
@@ -44,78 +44,82 @@ void isolateSpawnEntrypoint(SendPort port) {
}

void main() {
tearDown(() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing this tearDown with try {} finally {} in the tests.

import 'package:vm_service/vm_service.dart' as vms;
import 'package:vm_service/vm_service_io.dart';

void main() {
late vms.VmService vmService;

setUpAll(() async {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing setUpAll and tearDownAll by inlining the code directly into the single test.

@zanderso zanderso marked this pull request as ready for review May 19, 2021 16:11
@zanderso zanderso removed the Work in progress (WIP) Not ready (yet) for review! label May 19, 2021
@zanderso zanderso requested a review from dnfield May 19, 2021 16:11
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! Only a couple real change requests (the instantiateImageCodec, adding a smoke test, and not using FutureOr). Otherwise nits.

Comment on lines +404 to +408
'src/third_party/pkg/image':
Var('github_git') + '/brendan-duncan/image.git' + '@' + '3.0.2',

'src/third_party/pkg/petitparser':
Var('github_git') + '/petitparser/dart-petitparser' + '@' + '4.1.0',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These dependencies (and XML) could be painful to upgrade, which we'll eventually want to do. Can we just get rid of them?

It looks like we only use this to encode and write a PNG image. We should be able to do that via dart:ui.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This, of course, should be done in a separate PR, and I'm not terribly partial to whether it's done before or after this one lands)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in this PR, I think I should leave the test logic as-is, but I am totally on board with cutting down on the dependencies.

Comment on lines 51 to 56
expect(const Color(0x12345678), equals(const Color(0x12345678)));
expect(const Color(0x12345678), equals(Color(0x12345678))); // ignore: prefer_const_constructors
expect(const Color(0x12345678), isNot(equals(const Color(0x87654321))));
expect(const Color(0x12345678), isNot(equals(const NotAColor(0x12345678))));
expect(const NotAColor(0x12345678), isNot(equals(const Color(0x12345678))));
expect(const Color(0x12345678), notEquals(const Color(0x87654321)));
expect(const Color(0x12345678), notEquals(const NotAColor(0x12345678)));
expect(const NotAColor(0x12345678), notEquals(const Color(0x12345678)));
expect(const NotAColor(0x12345678), equals(const NotAColor(0x12345678)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'm not a fan of these kind of matchers anyway. I'd much rather just see expect(Color(...) == Color(...), true);, or even just make the second parameter to expect optional so that it more or less workslike assert.

That said, I like notEquals better than isNot(somethingElse(isNot(......

@dnfield
Copy link
Contributor

dnfield commented May 19, 2021

/cc @jonahwilliams @Hixie who will probably find this interesting.

@zanderso zanderso force-pushed the dart-test-rm-test branch 2 times, most recently from 1371d68 to f38a8cd Compare May 20, 2021 03:14
@jonahwilliams
Copy link
Member

Scandalous!

@zanderso zanderso force-pushed the dart-test-rm-test branch from f38a8cd to 9ffb882 Compare May 20, 2021 04:16
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zanderso zanderso merged commit dd24949 into flutter:master May 20, 2021
@zanderso zanderso deleted the dart-test-rm-test branch May 20, 2021 06:08
@zanderso
Copy link
Member Author

Thanks for the thorough review!

@Hixie
Copy link
Contributor

Hixie commented May 20, 2021

If we're finding a way to get rid of test let's go ever further: drop test() (it doesn't actually add anything), group() (ditto), expect() (you can use assert), and so on. It would be so much simpler if a test was just straight dart code that either exit with a 0 or a 1 based on pass or fail...

@zanderso zanderso mentioned this pull request May 20, 2021
9 tasks
@zanderso
Copy link
Member Author

group() we can drop. test() has some advantages:

  1. Each test can run in its own Zone without the unit test author worrying about Zones. This allows all tests to run even if one test has an unhandled asynchronous exception.
  2. The test driver can control the scheduling of tests. For example it can run them in a random order, or limit the number of concurrently running tests.

@Hixie
Copy link
Contributor

Hixie commented May 21, 2021

Those advantages could also be achieved by using different files for tests that need isolating from each other. That would have the advantage of actually isolating the tests, rather than only isolating some aspects of the tests (I frequently see issues where tests interfere with each other due to shared singletons, for example).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants