Cannot see what group
s and test
s are declared before tests start running
#1998
Labels
type-enhancement
A request for a change that isn't a bug
Alternative title:
Declarer
knows the test suite structure, but it's private.Overview
In Dart test files, I'd like to be able to know the test suite structure (the test and groups, and child groups, etc.) before the tests start executing.
lib/testsample.dart
test/testsample_test.dart
Why are almost all properties in
Declarer
private? It's not a public API anyway. Why not make some of them at least@protected
, so that developers could extendDeclarer
and inject it into a Zone, replacing the existing `Declarer?Workaround
We cannot access the test suite structure with
Declarer
object before the tests start executing, but once they start executing, inside of the test callback, we have access to current Zone'sInvoker
object, which gives us a way to learn about all the groups and tests that are declared in the Dart test file being currently executed.test/testsample_hacky_test.dart
It's quite hacky, but hey, it works.
Another possible workaround
Create some custom Declarer and override the methods that declare groups and tests:
Then inject it into
zoneValues
of the currentZone
.I haven't had time to explore this approach further, though, so that's all I've got for now.
Credits: @mateuszwojtczak
More context
I'm working on a test framework for Flutter (link).
I need to know the Dart test suite structure in advance (i.e. before any tests start running) so that I can "register" all of the tests. Why do I need to "register" the tests? So that the native tests of the Flutter app (native tests = Java/Kotlin
JUnit
tests on Android, Objective-C/SwiftXCTest
s on iOS) can request the execution of individual Dart tests (but to request execution of a test, it has to be first registered for it).In the perfect world, I'd like to be able to write a webservice like this:
Why do I need to call Dart tests from native tests? Because there's a wealth of tools that understand these native mobile test frameworks (such as
JUnit
andXCTest
), and almost none of them know that Dart and Flutter exist. So essentially, I'm building a compatibility layer between the world of native mobile tests, and the world of Flutter tests written in Dat. Flutter sorta-kinda provides this compatibility layer in its integration_test package, but it's very barebones and we're building something better.It's a quite complicated problem and there're many parts to it - to fully understand what I mean, see Flutter issue #115751 (+ read the comments there).
Issues in
dart-lang/test
might be related:The text was updated successfully, but these errors were encountered: