I'm making a library that provides both client & server side code. When making the tests, I would like to test the interactions from both sides.
So far I have at least this tests:
Server side:
@TestOn("vm")
import "package:test/test.dart";
import "dart:io";
//...
void main() {
HttpServer server = HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 4040)
//.then()...
Cliente side:
@TestOn("content-shell")
import "package:test/test.dart";
import "dart:html";
//...
void main(){
//Interact with server at 4040
What should I do to have all the tests ran with a single command? Is it possible?
The implementation that I proposed back in 2014 took advantage of the fact that Dart can run on the server and client, while gRPC makes it easy to switch languages on both sides.
A single test file can be run just using dart test path/to/test. dart (as of Dart 2.10 - prior sdk versions must use pub run test instead of dart test ). Many tests can be run at a time using dart test path/to/dir . It's also possible to run a test on the Dart VM only by invoking it using dart path/to/test.
@TestOn("content-shell")
doesn't make much sense in my opinion, except when this test shouldn't be run in other browsers. Use browser
instead.
Without @TestOn()
(default) the tests will be run on any platform. Only add @TestOn(...)
if you want to restrict where the test is run.
To run browser tests and server tests with a single command use
pub run test -pvm -pdartium -pchrome -pfirefox -pie -pblink
or a bit shorter
pub run test -pvm,dartium,chrome,firefox,ie,blink
The readme and the docs in https://github.com/dart-lang/test/tree/master/doc provide lots of details how to configure the test runner.
As stated in the docs provided by Günter, create dart_test.yaml in the package's root:
#dart_test.yaml
#run 2 test suites at the same time (I guess, that in 2 different cores)
concurrency: 2
Now run
pub run test test/server.dart test/client.dart -pvm,content-shell
If it takes long (generally on opening the browser) you could add to the same config file:
timeout: none #or i.e., 1m 30s
You can also save the -pvm,content-shell part of the command by seizing the config file:
platforms:
- vm
- content-shell
If this doesn't work, you could save the hours it took me figuring out what the heck happened by running:
pub cache repair
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With