Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create tests for each event constructor #186

Merged

Conversation

eliasyishak
Copy link
Contributor

@eliasyishak eliasyishak commented Oct 26, 2023

Closes issue:


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

Comment on lines +5 to +6
import 'dart:mirrors';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bkonyi i know using this package is a little "iffy", but in the context of this test file, i needed a way to ensure that each constructor was being tested from the Event class.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ehhhhhh, I wouldn't encourage use of dart:mirrors but I don't have an alternative for you. If this functionality works, you're probably fine to use it, but lots of dart:mirrors has been left to bit-rot and won't work with newer language features (anything >= Dart 2.0 could be partly broken or might just not work).

There might be a way to do this with package that utilizes code gen, but I'm not sure.

Comment on lines +315 to +327
var constructorCount = 0;
for (var declaration in reflectClass(Event).declarations.keys) {
if (declaration.toString().contains('Event.')) constructorCount++;
}

// Change this integer below if your PR either adds or removes
// an Event constructor
final eventsAccountedForInTests = 17;
expect(eventsAccountedForInTests, constructorCount,
reason: 'If you added or removed an event constructor, '
'ensure you have updated '
'`pkgs/unified_analytics/test/event_test.dart` '
'to reflect the changes made');
Copy link
Contributor Author

@eliasyishak eliasyishak Oct 26, 2023

Choose a reason for hiding this comment

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

This is the only test that uses the dart:mirrors by using reflectClass(...)

Comment on lines +320 to +322
// Change this integer below if your PR either adds or removes
// an Event constructor
final eventsAccountedForInTests = 17;
Copy link
Contributor

Choose a reason for hiding this comment

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

This test in particular strikes me as purely a change detection test. Should we instead trust future contributors and code reviewers to make sure the constructors are under test as they add/delete code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in this case it would make sense though because a contributor could forget to add a test for a newly added Event constructor, in which case this test would fail in presubmit checks so it can save time for a reviewer to flag.

Copy link
Contributor

@bkonyi bkonyi left a comment

Choose a reason for hiding this comment

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

The tests LGTM overall. There's probably a better way to check that we've covered all the various Event constructors, but I don't think it's worth blocking this.

@andrewkolos
Copy link
Contributor

Related to issue:

Should this be "closes #182"?

@eliasyishak
Copy link
Contributor Author

Related to issue:

Should this be "closes #182"?

Yep, I just have a bad habit of always writing related

@eliasyishak eliasyishak merged commit e828d45 into dart-lang:main Oct 27, 2023
6 checks passed
@eliasyishak eliasyishak deleted the 182-tests-for-each-event-constructor branch October 27, 2023 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants