This question already has an answer here:
WebStorm DartUnit with test api, run/debug error
(1 answer)
Closed 7 years ago.
This should be trivial but it is not working as I think it should. I am new to WebStorm.
I have a simple test taken from Dart's new test offering at https://pub.dartlang.org/packages/test
.dart
import "package:test/test.dart";
void main() {
test("String.split() splits the string on the delimiter", () {
var string = "foo,bar,baz";
expect(string.split(","), equals(["foo", "bar", "baz"]));
});
test("String.trim() removes surrounding whitespace", () {
var string = " foo ";
expect(string.trim(), equals("foo"));
});
}
Running this simple test gives the following exception:
J:\dart\dart-sdk\bin\dart.exe --ignore-unrecognized-flags --checked --package-root=J:\workspace\epimss\dart\epimss_shared\packages --enable-vm-service:60110 --trace_service_pause_events C:\Users\st.clair.clarke\AppData\Local\Temp\jetbrains_unit_config.dart
Testing started at 3:07 AM ...
Observatory listening on http://127.0.0.1:60110
Unhandled exception:
No top-level setter 'unittestConfiguration=' declared.
NoSuchMethodError: method not found: 'unittestConfiguration='
Receiver: top-level
Arguments: [Instance of 'JetBrainsUnitConfig']
#0 NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:188)
#1 main (file:///x:/Users/zang/AppData/Local/Temp/jetbrains_unit_config.dart:10:3)
#2 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:259)
#3 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
Process finished with exit code 255
The problem seems to be the line unittestConfiguration = config; in the jetbrains configuration - something is expected for the config.
Any help is appreciated.
According to this issue, test package is not yet supported by WebStorm's testing framework.
You have two ways right now:
Run it as usual dart application, not as a test
Use deprecated unittest package instead of test until issue is resolved.
Related
I'm building a program that use the Dart's AST library, and it works fine as long as I use the Dart interpreter to run the program (dart filename.dart).
Once I want to compile the program (dart compile filename.dart), the program can't load the file and I have this stacktrace:
#0 _PhysicalFile.readAsStringSync (package:analyzer/file_system/physical_file_system.dart:184)
#1 FolderBasedDartSdk.languageVersion (package:analyzer/src/dart/sdk/sdk.dart:400)
#2 FeatureSetProvider.build (package:analyzer/src/dart/analysis/feature_set_provider.dart:143)
#3 AnalysisDriver._createFileTracker (package:analyzer/src/dart/analysis/driver.dart:1500)
#4 new AnalysisDriver (package:analyzer/src/dart/analysis/driver.dart:291)
#5 ContextBuilder.buildDriver (package:analyzer/src/context/builder.dart:119)
#6 ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:94)
#7 new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:55)
#8 _createAnalysisContext (package:analyzer/dart/analysis/utilities.dart:125)
#9 resolveFile (package:analyzer/dart/analysis/utilities.dart:115)
#10 main (package:DartProjects/dartprojects.dart:122)
#11 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299)
#12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168)
I took a look at the source code to see where could be the error, and it seems that in package:analyzer/src/dart/sdk/sdk.dart it tries to get the langage version file, but instead of using the PATH to know where my dart sdk is, it tries to find it in my InteliJ folder, which fails. Also, I tried to run it on a freshly created VM, and it fails too.
Here is the code that produce this output:
import 'dart:io';
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
void main(List<String> arguments) async {
final fileName = Directory.current.path + r'\test.dart';
var source = null;
try {
source = await resolveFile(path: fileName);
} catch (e, s) {
print('${s}');
return;
}
}
Thanks for your help.
Not a good workaround.
Copy the "version" file from the Dart SDK folder to the root of your project.
The analyzer will take it and use it.
This will work if your compiled file is in the "bin" folder.
This is not a good workaround.
P.S.
This is called a hack.
I'm using appium-dotnet-driver v4.0.0.4 beta of the appium nuget package (but I have downgraded to the previous versions too and I'm getting the same issue)
So I've never used it before, therefore not entirely sure how it should work. Currently I'm doing this:
private static AppiumDriver<AppiumWebElement> mobileDriver;
AppiumOptions opt = new AppiumOptions();
opt.AddAdditionalCapability("autoWebview", true);
switch (platform.ToLower())
{
case "ios":
{
foreach (var cap in MobileSettingsFileConstants.iosCapabilities)
{
opt.AddAdditionalCapability(cap.Key, cap.Value);
}
mobileDriver = new IOSDriver<AppiumWebElement>(GridUri, opt);
break;
}
When ever it tries to add an additional capability to Appium Options I get an exception : Exception thrown: 'System.MissingMethodException' in appium-dotnet-driver.dll, Additional information: Method not found: 'Void OpenQA.Selenium.Remote.DesiredCapabilities.set_Item
I've had a look on the appium forum and they said this was an issue. Can someone share their experience with this please?
I found out I had to be at the latest version on Selenium on both test framework and test solution.
Simple answer to a mind boggling question.
I've been using the Guinness test framework for some functional testing in my Dart library.
I think one of the new updates to either WebStorm or Dart SDK broke.
I have the following:
import 'package:guinness/guinness.dart';
import 'package:tickets/shared/schemas.dart';
import 'package:tickets/db/seeder.dart';
import 'package:tickets/db/db_config.dart';
import '../bin/mongo_model.dart';
main() {
DbConfigValues config = new DbConfigValues();
MongoModel model = new MongoModel(config.testDbName, config.testDbURI, config.testDbSize);
//A Test DTO
RouteDTO routeDTO = new RouteDTO()..duration=120..price1=90.00..price2=91.00..price3=95.00..seats=7;
describe("The Ticket MongoModel", () {
it("should create a record DTO and write to the db", () {
var originalID = routeDTO.id;
return model.createByItem(routeDTO).then(( var dto ) {
expect(originalID).toBeNull();
expect(routeDTO.id).toBeNotNull();
expect(dto.id).toEqual(routeDTO.id);
});
});
});
}
Which results in:
/usr/local/opt/dart/libexec/bin/dart --ignore-unrecognized-flags --checked --enable-vm-service:52158 --trace_service_pause_events /private/var/folders/br/4n3vt5lj0qq11xk0fdmjk9y80000gn/T/jetbrains_unit_config.dart
Testing started at 3:31 PM ...
Unhandled exception:
Could not resolve a package location for base at file:///private/var/folders/br/4n3vt5lj0qq11xk0fdmjk9y80000gn/T/jetbrains_unit_config.dart
#0 _handlePackagesReply (dart:_builtin:416)
#1 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
Observatory listening on http://127.0.0.1:52158
Process finished with exit code 255
Question: How do i get guiness working with WebStorm in 11EAP.
I suggest to run the test as a standard command line Dart application. You can create corresponding run configuration manually (Run | Edit Configurations | [+] | Dart Command Line App), or remove current DartUnit run configuraton (Run | Edit Configurations) and then right click the main file. You won't get test result tree this way, but you'll see test results in the IDE console.
According to Alexanders answer I found a solution for me - I'm using the bash plugin for this...
I have a new dart project but I fail to add unit tests.
But I am new to DART so perhaps I am punished as all rookies should ... or should they!?
Error when running unit tests
Error: Exception: No constructor 'Future.value' declared in class 'Future'.
NoSuchMethodError : method not found: 'Future.value'
Receiver: Type: class 'Future'
Arguments: []
Stack Trace: #0 _defer (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/packages/unittest/unittest.dart:671:20)
#1 _ensureInitialized (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/packages/unittest/unittest.dart:830:11)
#2 ensureInitialized (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/packages/unittest/unittest.dart:809:21)
#3 group (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/packages/unittest/unittest.dart:585:20)
#4 main (http://127.0.0.1:3030/Users/gunnar/git/chessbuddy/src/main/webapp/dart/chessmodel/test/test_runner.dart:9:8)
FAIL
pub info
€ pub --version
Pub 0.4.7+1.r21548
€ pub cache list
{"packages":
{"browser":{"version":"0.4.7+1","location":"/Users/gunnar/.pub-cache/hosted/pub.dartlang.org/browser-0.4.7+1"},
"meta":{"version":"0.4.7+1","location":"/Users/gunnar/.pub-cache/hosted/pub.dartlang.org/meta-0.4.7+1"},
"stagexl":{"version":"0.7.4","location":"/Users/gunnar/.pub-cache/hosted/pub.dartlang.org/stagexl-0.7.4"},
"unittest":{"version":"0.4.7+1","location":"/Users/gunnar/.pub-cache/hosted/pub.dartlang.org/unittest-0.4.7+1"}}}
Eclipse plugin
Dart Editor for Eclipse 0.4.7.r21548 com.google.dart.eclipse.feature.feature.group dartlang.org
test_runner.dart
import 'package:unittest/unittest.dart';
import 'package:unittest/html_enhanced_config.dart';
import 'ChessColor_test.dart' as color_test;
void main() {
useHtmlEnhancedConfiguration();
group('Enum tests', color_test.main);
}
ChessColor_test.dart
library color_test;
import 'package:unittest/unittest.dart';
void main() {
test('isWhite', () =>
expect(true, WHITE.isWhite())
);
}
A couple of things to try:
Take a look at dart-sdk/lib/async/future.dart. Do you see a Future.value factory constructor? If not, then your SDK is not the right version. I would check this both from the command line and from within the editor.
If you do see it in the SDK, try exiting and restarting the editor. I'm speculating here, but when we saw this once in house, it behaved as though there was a cached copy of the async library that was out of date, and restarting made the issue go way.
I using Dart Editor 0.3.7_r18717 (means the editor is up to date (Feb 2013)
import 'dart:intl';
Shows an error "Cannot find referenced source"
If I import the package via pub
import 'package:intl/intl.dart';
then compiling to JS dart2js fails with some weird errors...
What I want is simply something like this:
final String time = new DateFormat("HH:mm:ss","de").format(new DateTime.now());
It's not clear at all why the locale is needed in such case...
thx
[Update]
OK - I know "weird errors" means nothing - so here is the output if I import the following two packages:
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
String getTime() {
final String time = new DateFormat("HH:mm:ss","en_US").format(new DateTime.now());
//final String time = "20:05:00";
return time;
}
Output:
Running dart2js...
Using snapshot /Developer/dart/dart-sdk/lib/_internal/compiler/implementation/dart2js.dart.snapshot
Wrote /Users/mikemitterer/dart/WebSockets.SAMPLE/web/out/jrelaisui.html_bootstrap.dart.js [410.0kb written in 5.3 seconds]
build.dart --machine --changed=web/jrelaisui.dart
file:/Users/mikemitterer/dart/WebSockets.SAMPLE/build.dart
build.dart returned error code 255
Uncaught Error: NoSuchMethodError : method not found: '_addFromInteger#0x36924d72'
Receiver: null
Arguments: [80]
Stack Trace:
#0 Object.noSuchMethod (dart:core-patch:1737:25)
#1 int.+ (dart:core-patch:1324:33)
#2 Parser.translateCharacter (package:analyzer_experimental/src/generated/parser.dart:4380:167)
#3 Parser.computeStringValue (package:analyzer_experimental/src/generated/parser.dart:376:33)
#4 Parser.parseStringLiteral (package:analyzer_experimental/src/generated/parser.dart:3451:76)
#5 Parser.parsePrimaryExpression (package:analyzer_experimental/src/generated/parser.dart:3163:32)
#6 Parser.parseAssignableExpression (package:analyzer_experimental/src/generated/parser.dart:837:51)
#7 Parser.parsePostfixExpression (package:analyzer_experimental/src/generated/parser.dart:3061:51)
...
Output - Clean Up Source:
build.dart --machine --clean
file:/Users/mikemitterer/dart/HelloWebComponent/build.dart
build.dart returned error code 255
'package:html5lib/src/encoding_parser.dart': Error: line 65 pos 14: class 'EncodingBytes' overrides function 'skip' of super class 'Iterable' with incompatible parameters
String skip([CharPreciate skipChars]) {
^
build.dart --machine --clean
file:/Users/mikemitterer/dart/todomvc/build.dart
build.dart returned error code 255
'package:html5lib/src/encoding_parser.dart': Error: line 65 pos 14: class 'EncodingBytes' overrides function 'skip' of super class 'Iterable' with incompatible parameters
String skip([CharPreciate skipChars]) {
...
Thats what I mean with "weird" :-)
The package syntax is the correct one, this should work:
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
main() {
print(new DateFormat.yMd().format(new DateTime.now()));
}
What "weird errors" are you talking about?
import "dart:intl"; won't work to import it because it's not one of the "core" dart libraries, it has to be imported as a package. The errors you're listing in dart2js don't look like they're coming from internationalization code, but from web_ui and from the analyzer_experimental package. What happens if you comment out the lines that use internationalization and compile using dart2js?