AngularDart 5(alpha)测试命令执行异常问题求助
Hey there, let's sort out this testing headache with AngularDart 5 alpha—those outdated docs can be a real pain, right? Let's break down why you're seeing those two issues and how to fix them.
First: Why "No tests ran"?
Most likely, build_runner can't find your test files, or they don't follow the expected naming/convention rules:
- Your test files need to live in the
test/directory (or a subfolder under it) and end with_test.dart(likeapp_component_test.dart). Build_runner uses this pattern to auto-discover tests by default. - Double-check that you've imported the necessary Angular testing libraries in your test files (like
package:angular_test/angular_test.dart)—without that, even if the file is found, it might not register any test cases.
Second: Why the "dart:html not available" crash?
AngularDart component tests rely on browser APIs (hence dart:html), but the default pub run build_runner test command runs tests in a VM environment (which doesn't have browser APIs). You need to explicitly tell it to use a browser platform.
The Fix: Correct Test Command & Setup
Here's what you need to do step by step:
Verify your dev dependencies in
pubspec.yaml(make sure they're compatible with AngularDart 5 alpha):dev_dependencies: angular_test: ^5.0.0-alpha build_test: ^2.1.0 test: ^1.24.0Run
pub getto ensure these are installed.Use the right build_runner command that targets a browser:
# Run all tests in headless Chrome (great for CI) pub run build_runner test --platform chrome --headless # Or run tests in a visible Chrome window pub run build_runner test --platform chrome # Run a single test file if you don't want to run everything pub run build_runner test --platform chrome test/app_component_test.dartOptional: Customize test discovery (if needed)
If your tests are in non-standard paths, create abuild.yamlfile in your project root to tell build_runner where to look:targets: $default: builders: build_test:test_config: generate_for: - test/**/*_test.dart # Add any other paths here if your tests are elsewhere
Quick Recap
The core issue was that you weren't specifying the browser platform—without that, build_runner tries to run Angular tests in a VM which can't handle dart:html. And the "No tests ran" problem was either missing the right file naming/convention or incorrect dependencies.
Give these steps a shot, and you should have your AngularDart 5 alpha tests running smoothly!
内容的提问来源于stack exchange,提问作者Rémi Rousselet

