testing - 例外:为 FeatureFile 'CommentLineRunnable' 提供了未知的可运行子项
问题描述
我在我的颤振应用程序中编写了 BDD 测试用例。我在项目终端中运行 dart test_driver/test_config.dart 时收到“异常:给 FeatureFile 'CommentLineRunnable' 的未知可运行子项”。
我的 test_config.dart 文件:
import 'dart:async';
import 'package:glob/glob.dart';
import 'package:gherkin/gherkin.dart';
import 'package:flutter_gherkin/flutter_gherkin.dart';
import './steps/loginPage_test.dart';
Future<void> main() {
final config = FlutterTestConfiguration()
..features = [Glob(r"test_driver/features/**.feature")]
..stepDefinitions = [
LoginPageValidation(),
PasswordValidation(),
LoginButton(),
NavValidation()
]
..reporters = [ProgressReporter(), TestRunSummaryReporter(), JsonReporter()]
..restartAppBetweenScenarios = true
..targetAppPath = "test_driver/app.dart"
..exitAfterTestRun = true;
return GherkinRunner().execute(config);
}
我收到的错误消息是:
Unhandled exception:
Exception: Unknown runnable child given to FeatureFile 'CommentLineRunnable'
#0 FeatureFile.addChild (package:gherkin/src/gherkin/runnables/feature_file.dart:41:9)
#1 GherkinParser._parseBlock (package:gherkin/src/gherkin/parser.dart:119:21)
#2 GherkinParser.parseFeatureFile (package:gherkin/src/gherkin/parser.dart:55:7)
<asynchronous suspension>
#3 GherkinRunner.execute (package:gherkin/src/test_runner.dart:47:43)
<asynchronous suspension>
#4 main (file:///home/al029/Altorum_Projects/altorum-operation-flutter/test_driver/test_config.dart:22:26)
#5 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:305:19)
#6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
解决方案
通过从我的功能文件中删除注释解决了这个问题,但我不明白为什么功能文件中的注释会导致问题。
# Login Page test
Feature: Login
User should be able to login successfully after clicking login button.
Scenario: User logs in successfully
Given I expect the user enters email
And I expect the user enters password
When user hits Login button
Then user should land on next screen
我删除了评论
Feature: Login
User should be able to login successfully after clicking login button.
Scenario: User logs in successfully
Given I expect the user enters email
And I expect the user enters password
When user hits Login button
Then user should land on next screen
它工作得很好。