WebStorm 11 EAP - Dart Unit Test Throwing Errors - dart

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...

Related

How to solve Not found: 'dart:ui' error while running integration tests on Flutter

I have an app, it is very simple and have just one widget. It is working fine, however when I run integration test by calling:
$ flutter drive --target=test_driver/app.dart
I get the following error:
file:///Users/myuser/flutter/packages/flutter_test/lib/src/accessibility.dart:8:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;
^
file:///Users/myuser/flutter/packages/flutter_test/lib/src/binding.dart:8:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;
^
file:///Users/myuser/flutter/packages/flutter_test/lib/src/matchers.dart:8:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;
^
file:///Users/myuser/flutter/packages/flutter_test/lib/src/matchers.dart:9:8: Error: Not found: 'dart:ui'
import 'dart:ui';
^
file:///Users/myuser/flutter/packages/flutter_test/lib/src/test_pointer.dart:12:1: Error: Not found: 'dart:ui'
export 'dart:ui' show Offset;
^
file:///Users/myuser/flutter/packages/flutter/lib/src/rendering/binding.dart:8:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show window;
^
file:///Users/myuser/flutter/packages/flutter/lib/src/rendering/box.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show lerpDouble;
^
file:///Users/myuser/flutter/packages/flutter/lib/src/rendering/debug_overflow_indicator.dart:6:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui;
^
file:///Users/myuser/flutter/packages/flutter/lib/src/rendering/editable.dart:8:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show TextBox;
^
file:///Users/myuser/flutter/packages/flutter/lib/src/rendering/error.dart:5:8: Error: Not found: 'dart:ui'
import 'dart:ui' as ui show Paragraph, ParagraphBuilder, ParagraphConstraints, ParagraphStyle, TextStyle;
^
Stopping application instance.
Driver tests failed: 254
Note that when I run the app from Android Studio, it runs successfully. But when I run from terminal using the command quoted above, the app shows a white screen and it doesn't move from there until I get the error on my terminal.
Assuming it's a path issue, like test_driver not finding flutter packages like dart:ui, how can I make sure test_driver knows where dart:ui is ?
Make sure that the import is set to this:
import 'package:test/test.dart';
instead of this:
import 'package:flutter_test/flutter_test.dart';
The integration tests can have no imports to your main App code or other flutter code that runs in the App - otherwise they will fail with your seen error.
Have a read of https://flutter.io/cookbook/testing/integration-test-introduction/ as this gives an example of integration tests with an app starting point that allows you to run setup code before your actual driver tests run if this is what you are looking to do. Otherwise don't use key values that use constants from your main code (as mentioned here http://cogitas.net/write-integration-test-flutter/).
This is old post, but I found another possible reason why test gave me this error:
When I was creating new Bloc class I created constructor with #required annotation and when I used Option+Enter for importing appropriate library, Android Studio imported 'package:flutter/cupertino.dart' library instead of 'package:meta/meta.dart' and that is the reason my unit test didn't start in the first place.
After importing correct library, all tests have passed!
Happy testing your code! :D
Here is the solution for adding these test cases:
In Android studio in the run dropdown you
select Edit Configurations
Press the + button and select Flutter test
Make sure the Test scope is All in file and point it at your test file.
You can now run the individual test file and also debug it in android studio by selecting this configuration in the run drop-down.
Remove all imports to package:flutter/... from the test driver's code, like:
import 'package:flutter/widgets.dart';
I was getting these erros because I was trying to import a widget on a test_driver file. I also got the same error if I try to use find.byWidget.
I was trying to import a widget or use find.byWidget because I wanted to check the existence of a widget on a screen.
These erros are pretty much similar to
The built-in library 'dart:ui' is not available on the stand-alone VM.
Then, in order to check the existence of a widget on screen in a test_driver file, I had to use find.byKeyValue. For example, given the following dummy widget, defined in a file within my app:
class MyDummyWidget extends StatelessWidget {
MyDummyWidget(): super(key: new Key('MyDummyWidget'));
#override
Widget build(BuildContext context) {
return Center();
}
}
To check if it is being displayed on screen, I define the following test within the test_driver:
void main() {
group('My tests', () {
FlutterDriver driver;
SerializableFinder myDummyWidget = find.byValueKey('MyDummyWidget');
setUpAll(() async {
driver = await FlutterDriver.connect();
});
tearDownAll(() async {
if (driver != null) {
driver.close();
}
});
test('check if MyDummyWidget is being displayed', () async {
await driver.waitFor(myDummyWidget);
});
});
}
Where the key definition is the required one in the first file, and then, the find.byValueKey and await driver ones are the essentials in the test file.
Don't simply run the test. It is running the pp virtually. So we can't import dart: UI. It'll give the error. Use command
flutter drive --target=test_driver/app.dart to test it.
In Android Studio, right-click on the test file in the Project tree and select "Run". You should see 2 options:
Make sure you select the second option: "tests in widget_test..."
If you select the first option you will see the Error: Not found: 'dart:ui' and you lose the option to make a selection from the Run context menu.
Finally, I got run widget tests in my app.
This soluction worked for me.
I found out why, I chose the first option instead of the flutter test. how silly I was, now removing this wrong test type from configuration and run with flutter test works now.
See the image about run in Android Studio
Just check that you don't have imports which load flutter packages.
In my case I had 'cupertino' package import from my file app_keys.dart which listed all keys in a format Key('<something>').
BUT!! UI tests use Key('<something>') constants for Finder but Integration tests - simple strings.
Reference

using the server variable in ember-cli-mirage tests

I'm trying to use ember-cli-mirage in my tests but running into problems. I'm using ember and ember-data 2.1.0 so that may have something to do with this.
I'm able to use mirage in development just fine. I've defined factories, routes, scenarios, etc with no problem.
The problem is when i attempt to create models in tests. The test below errors out:
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'frontend/tests/helpers/start-app';
let application;
module('Acceptance | Customer', {
beforeEach() {
application = startApp();
},
afterEach() {
Ember.run(application, 'destroy');
}
});
test('viewing customers', function(assert) {
server.createList('customer', 2);
visit('/admin/customers');
andThen(() => assert.equal(find('#customers-table tbody tr').length, 2));
});
This results in:
not ok 1 PhantomJS 1.9 - Acceptance | Customer: viewing customers
---
actual: >
null
message: >
Died on test #1 at http://localhost:7357/assets/test-support.js:3124
at http://localhost:7357/assets/frontend.js:2434
at http://localhost:7357/assets/vendor.js:150
at tryFinally (http://localhost:7357/assets/vendor.js:30)
at http://localhost:7357/assets/vendor.js:156
at http://localhost:7357/assets/test-loader.js:29
at http://localhost:7357/assets/test-loader.js:21
at http://localhost:7357/assets/test-loader.js:40
at http://localhost:7357/assets/test-support.js:6846: 'undefined' is not a function (evaluating 'newCollection[method].bind(newCollection)')
Log: |
...
Should I be bootstrapping mirage somewhere?
This is actually caused by Phantom 1.9 not having bind (you can see in the error message, undefined refers to bind).
If you view the other notes section of the Installation docs you'll see you can get around this by installing ember-cli-es5-shim (or upgrading to PhantomJS 2.0).

Running a simple Dart test in WebStorm 10.0.4 [duplicate]

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.

Can not run unit test: No constructor 'Future.value' declared in class 'Future'

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.

javac will not compile enum, ( Windows Sun 1.6 --> OpenJDK 1.6)

package com.scheduler.process;
public class Process {
public enum state {
NOT_SUBMITTED, SUBMITTED, BLOCKED, READY, RUNNING, COMPLETED
}
private state currentState;
public state getCurrentState() {
return currentState;
}
public void setCurrentState(state currentState) {
this.currentState = currentState;
}
}
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
Modified the example to try and direct to the issue. I cannot change the state on this code. Eclipse suggests importing Process.state like I had on my previous example, but this doesn't work either. This allows state s = state.READY but the call to p.setCurrentState(s); fails as does p.setCurrentState(state.READY);
Problem continued.... Following Oleg's suggestions I tried more permutations:
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.*;
public class Machine {
com.scheduler.process.Process p = new com.scheduler.process.Process();
public state s = Process.state.READY;
p.setCurrentState(s);
p.setCurrentState(state.READY);
}
Okay. It's clear now that I'm a candidate for lobotomy.
package com.scheduler.machine;
import com.scheduler.process.Process;
import com.scheduler.process.Process.state;
public class Machine {
public void doStuff(){
com.scheduler.process.Process p = new com.scheduler.process.Process();
state s = state.READY; //fails if I don't also explicitly import Process.state
p.setCurrentState(s); //says I need a declarator id after 's'... this is wrong.
p.setCurrentState(state.READY);
}
}
I needed to have a method in the class--but we're still missing something (probably obvious) here. When I go via the command line and run javac on the Machine class AFTER compiling Process, I still get the following error:
mseil#context:/media/MULTIMEDIA/Scratch/Scratch/src/com/scheduler/machine$ javac Machine.java
Machine.java:3: package com.scheduler.process does not exist
import com.scheduler.process.Process;
^
So I guess the question now becomes, what idiot thing am I missing that is preventing me from compiling this by hand that eclipse is doing for me behind the scene?
======
Problem solved here:
Java generics code compiles in eclipse but not in command line
This has just worked for me:
Download latest Eclipse
Create new project
Create two packages com.scheduler.process and com.scheduler.machine
Create class Process in package com.scheduler.process and class Machine in com.scheduler.machine and copy their contents from your post modifying them to conform to Java language syntax, like this:
Everything compiles right away.
------ to answer the previous version of the question ------
To answer the question as it is right now: you need to either
import com.scheduler.process.Process.status or import com.scheduler.process.Process.* and refer to status as just status
or
import com.scheduler.process.* or import com.scheduler.process.Process and refer to status as Process.status
------ to answer the original version of the question ------
You can't import classes that are not inside some package. You just can't. It is a compile time error to import a type from the unnamed package.
You don't need to import anything if your classes are in the same package, or if all of your classes are packageless.
If Process class was inside some package it would be possible to import just its status inner class: import a.b.c.Process.status would work just fine.
All your Windows/Linux migration issues don't have anything to do with Java and exceptions that you see. import Process.state; will produce exception on any OS because you can't import classes that don't belong to any package.
Eclipse doesn't use the Sun JDK by default. I would assume that you are using Eclipse's built in compiler as Sun's JDK and the OpenJDK are almost identical.
Java code compiles and runs exact the same on Windows and Linux most of the time (unless you use a few of the platform specific operations)
I suspect you are not building the code the same way and when you compile Machine, the Process class has not been compiled.
I suggest you use a standard build system like maven or ant and it will build the same everywhere. Failing that run Eclipse on Linux or just the same .class you use on windows as they don't need to be re-compiled in any case.
BTW: You don't need to import Process.state as it not used and its in the same package (so you wouldn't need to if you did)

Resources