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
Recently I spent quite some time to figure it out the issue with my unit test. The error that I saw in my unit test is :
Ambiguous type name 'AssetIdentifier' in 'UIImage'
This is the complete code :
import XCTest
import module
#testable import module
class VoucherOptionsViewControllerTests: XCTestCase {
lazy var result = ""
class VoucherOptionsViewControllerMock: VoucherOptionsViewController {
var result = ""
override func showOverlayView(title: String, message: String, assetIdentifier: UIImage.AssetIdentifier) {
self.result = "lalalala"
}
}
}
AssetIdentifier is an enum in UIImage extension
I tried the suggestion listed in:
Ambiguous type name error
However, it returns me with a different error on the controller:
'AssetIdentifier' is inaccessible due to 'internal' protection level
I've tried to clean and rebuild but it returns the same error.
I think your issue lays in the double import of the module module.
import module
#testable import module
By importing it twice you give the compiler two (identical) versions of every type and function defined in module. That's why it's complaining about the ambiguity of AssetIdentifier, there's two of those and it doesn't know which to pick.
The right thing to do would be to remove import module though.
The #testable import statement allows you to import a module in your test target and to gain access to the types and functions defined internal as well as public.
When you add the #testable attribute to an import statement for a module compiled with testing enabled, you activate the elevated access for that module in that scope. Classes and class members marked as internal or public behave as if they were marked open. Other entities marked as internal act as if they were declared public.
Source.
If you do that you'll see that you won't have ambiguity issues and you won't need to move the UIImage extension in the test target. As #JonReid rightfully pointed out in his comment "Production code should remain in your production target".
Hope this helps.
Although that thread does not give the real answer, it gives great clue about the issue. So the fix that I found is by removing :
#testable import module
I keep the UIImage extension in the test module so the compiler does not complain.
I'm using node.js API from compiled Dart app. With package:js bindings for this api's:
#JS('http')
library http;
import "package:js/js.dart";
external Server createServer(
[ void requestListener(IncomingMessage request, ServerResponse response)])
And calling this from main.dart:
import "package:js/js.dart";
import "node_partly.dart" as http;
main() async {
http.Server server = http.createServer(allowInterop(handler));
server.listen(9876);
}
void handler(http.IncomingMessage request, http.ServerResponse response){
response.write("Hello, from dart server! \n");
response.write("You asked for ${request.url}");
print(request.url);
response.end();
}
Everything works fine.
But. Analyzer fails with error
WARNING: The argument type 'JSFunction' cannot be assigned to the
parameter type '(IncomingMessage, ServerResponse) → void'. (
example/main.dart:5)
The problem is that allowInterop produces "JSFunction" - deprecated class for internal use.
And from point of view of annotations - there should be normal "Function" class.
This is annoying if to pay attention to this. And if I will not pay attention to analyzer errors - I may leave real error in my code.
How can I fix it?
P.S. Using latest dart 1.16
Update: created issue at github https://github.com/dart-lang/sdk/issues/26371
I am migrating an old JSF application from WAS 6.x to WAS 8.x and I am getting the following compilation error:
The import com.ibm.faces cannot be resolved
This comes from the following code:
import com.ibm.faces.component.html.HtmlScriptCollector;
...
protected HtmlScriptCollector onLoadCollector;
How do I port this for use on WAS 8.x?
Looks so far like these methods can just be removed. A better explanation will get the check.
I am trying to run the latest version of its_all_about_you with the latest version of Dart Editor/SDK and I am getting this error. I copied the latest source from github
Internal error: 'http://.../web/out/packages/web_ui/src/linked_list.dart':
Error: line 72 pos 29: cannot resolve class name 'IterableBase' from 'LinkedList'
class LinkedList<E> extends IterableBase<E> {
Does anyone know what the problem is and how to fix it? And for future reference how would one go about debugging the issue?
This looks like a version mismatch. Could you please verify that your sdk (comes with the editor) is up to date.
If the error persists after an upgrade, post the version number of your editor and try the following (untested) example:
import 'dart:collection';
class A extends IterableBase { get iterator => null; }
main() { new A(); }
In recent versions of Dart this should work.