Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

@jiahaog
Copy link
Member

@jiahaog jiahaog commented Oct 21, 2020

Description

This integrates with directRunTests from package:test_core, and allows users to use test() to wrap their tests, instead of only supporting testWidgets() and failing silently otherwise. In addition, exceptions thrown in other lifecycle blocks such as setUp will be caught and reported.

This is a non-breaking change, so the existing reporting mechanism will continue to work. A global variable is used to ensure that using run will disable the existing reporting mechanism.

Example usage

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

void main() => run(_testMain);

void _testMain() {
  test('A test', () {
    expect(true, true);
  });
}

But we will want to make it easier for users to use this API. A CLI will be added as a follow up PR to wrap this method as part of flutter/flutter#66264, so users can write the following instead, and the CLI will take care of wrapping the users' script with run appropriately.

import 'package:flutter_test/flutter_test.dart';

void main() {
  test('A test', () {
    expect(true, true);
  });
}

Related Issues

Fixes flutter/flutter#50816.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

…sults

This integrates with `directRunTests` from `package:test_core`, and allows users to use `test()` to wrap their tests, instead of only supporting `testWidgets()` and failing silently otherwise. In addition, exceptions thrown in other lifecycle blocks such as `setUp` will be caught and reported.

This is a non-breaking change, so the existing reporting mechanism will continue to work. A global variable is used to ensure that using `run` will disable the existing reporting mechanism.

Fixes #50816.
@google-cla google-cla bot added the cla: yes label Oct 21, 2020
Copy link
Member Author

@jiahaog jiahaog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending this draft for review first for preliminary feedback – this is still pending a release from package:test_core so that we can use directRunTests.

I also want to restructure the tests a bit, and do a bit more testing locally to ensure that nothing is broken

@jiahaog jiahaog requested a review from dnfield October 21, 2020 13:22
},
);
} on MissingPluginException {
print('Warning: integration_test test plugin was not detected.');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be treated as a more serious failure, and probably make us exit with some non-zero exit code.

The risk is that if this isn't set up right in the application, it will print what looks like a warning in a sea of log output and exit with zero when tests may have failed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want the application to exit when it is invoked using flutter driver, as the native plugin is not used. The platform side plugin is only used when running with FTL or through Xcode. The responsibility of failing when the infrastructure is not set up properly (i.e. the native plugin is not installed) should probably be up to the host side invoker though, and probably not here.

Comment on lines +7 to +8
import 'package:test_core/src/runner/engine.dart';
import 'package:test_core/src/runner/reporter.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give warnings right?

We should probably pin the dependency for this to make sure we don't inadventently get broken by a patch release that changes internals.

I'm also surprised we don't need analysis ignores here, like // ignore: implementation_import or something. We should enable that lint and add the ignore here.

Copy link
Member Author

@jiahaog jiahaog Oct 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the lint isn't set up for this. This is a bit out of scope of this PR though – I have started #3187 to see if we can turn on the lint. There are some existing violation for this lint in the repo, will follow up tomorrow.

liveTest.test.name: liveTest.state.result.name == success
? success
: Failure(
liveTest.test.name, liveTest.errors.first.stackTrace.toString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the first stack trace the right one?

Is the first error the right one?

Is there some way we could add all stack traces and errors to the reporting?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was taken from the way other Dart tests are integrated with the Google3 infrastructure. I'm not sure if we should do anything else, @natebosch would you know more about this?

flutter_test:
sdk: flutter
path: ^1.6.4
test_core:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be updated now

Suggested change
test_core:
test_core: 0.3.12-nullsafety.6

Unfortunately null safety leaves us in a state where we'll need to pin to a single version since we can't really pin to a feature version currently.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I updated it but there's a conflict with flutter_test that is pinned to the previous version. I have opened flutter/flutter#68771 to update that separately.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty exciting - this will fix several classes of problems users can run into currently with the package!

@flutter flutter deleted a comment from natebosch Oct 22, 2020
@flutter flutter deleted a comment from natebosch Oct 22, 2020
@jiahaog jiahaog marked this pull request as ready for review October 22, 2020 12:49
@jiahaog
Copy link
Member Author

jiahaog commented Oct 22, 2020

Still pending flutter/flutter#68771 for CI to pass, but this is ready for review now.

@jiahaog jiahaog requested a review from natebosch October 22, 2020 13:43
@jiahaog
Copy link
Member Author

jiahaog commented Nov 9, 2020

package:integration_test is being moved to the SDK repo, so this PR is superseded by flutter/flutter#70075

@jiahaog jiahaog closed this Nov 9, 2020
@jiahaog jiahaog deleted the integration-test-reporter branch November 9, 2020 07:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make E2E use a custom test reporter so that invoking test() will work.

3 participants