commit | 93b69ef20d44ce2d94f3795904c662e5e6078d8b | [log] [tgz] |
---|---|---|
author | dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> | Sat Jul 01 23:46:15 2023 +0000 |
committer | GitHub <noreply@github.com> | Sat Jul 01 23:46:15 2023 +0000 |
tree | 8a8fb2713534058dd5e3cc8f30150dbfce8eda33 | |
parent | a926a6316d647ac67a07628227432f37c348612a [diff] |
Bump actions/checkout from 3.5.2 to 3.5.3 (#669) Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.2 to 3.5.3. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/actions/checkout/releases">actions/checkout's releases</a>.</em></p> <blockquote> <h2>v3.5.3</h2> <h2>What's Changed</h2> <ul> <li>Fix: Checkout Issue in self hosted runner due to faulty submodule check-ins by <a href="https://github.com/megamanics"><code>@âmegamanics</code></a> in <a href="https://redirect.github.com/actions/checkout/pull/1196">actions/checkout#1196</a></li> <li>Fix typos found by codespell by <a href="https://github.com/DimitriPapadopoulos"><code>@âDimitriPapadopoulos</code></a> in <a href="https://redirect.github.com/actions/checkout/pull/1287">actions/checkout#1287</a></li> <li>Add support for sparse checkouts by <a href="https://github.com/dscho"><code>@âdscho</code></a> and <a href="https://github.com/dfdez"><code>@âdfdez</code></a> in <a href="https://redirect.github.com/actions/checkout/pull/1369">actions/checkout#1369</a></li> <li>Release v3.5.3 by <a href="https://github.com/TingluoHuang"><code>@âTingluoHuang</code></a> in <a href="https://redirect.github.com/actions/checkout/pull/1376">actions/checkout#1376</a></li> </ul> <h2>New Contributors</h2> <ul> <li><a href="https://github.com/megamanics"><code>@âmegamanics</code></a> made their first contribution in <a href="https://redirect.github.com/actions/checkout/pull/1196">actions/checkout#1196</a></li> <li><a href="https://github.com/DimitriPapadopoulos"><code>@âDimitriPapadopoulos</code></a> made their first contribution in <a href="https://redirect.github.com/actions/checkout/pull/1287">actions/checkout#1287</a></li> <li><a href="https://github.com/dfdez"><code>@âdfdez</code></a> made their first contribution in <a href="https://redirect.github.com/actions/checkout/pull/1369">actions/checkout#1369</a></li> </ul> <p><strong>Full Changelog</strong>: <a href="https://github.com/actions/checkout/compare/v3...v3.5.3">https://github.com/actions/checkout/compare/v3...v3.5.3</a></p> </blockquote> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/actions/checkout/blob/main/CHANGELOG.md">actions/checkout's changelog</a>.</em></p> <blockquote> <h1>Changelog</h1> <h2>v3.5.3</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/1196">Fix: Checkout fail in self-hosted runners when faulty submodule are checked-in</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/1287">Fix typos found by codespell</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/1369">Add support for sparse checkouts</a></li> </ul> <h2>v3.5.2</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/1289">Fix api endpoint for GHES</a></li> </ul> <h2>v3.5.1</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/1246">Fix slow checkout on Windows</a></li> </ul> <h2>v3.5.0</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/1237">Add new public key for known_hosts</a></li> </ul> <h2>v3.4.0</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/1209">Upgrade codeql actions to v2</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/1210">Upgrade dependencies</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/1225">Upgrade <code>@âactions/io</code></a></li> </ul> <h2>v3.3.0</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/1045">Implement branch list using callbacks from exec function</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/1050">Add in explicit reference to private checkout options</a></li> <li>[Fix comment typos (that got added in <a href="https://redirect.github.com/actions/checkout/issues/770">#770</a>)](<a href="https://redirect.github.com/actions/checkout/pull/1057">actions/checkout#1057</a>)</li> </ul> <h2>v3.2.0</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/942">Add GitHub Action to perform release</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/967">Fix status badge</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/1002">Replace datadog/squid with ubuntu/squid Docker image</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/964">Wrap pipeline commands for submoduleForeach in quotes</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/1029">Update <code>@âactions/io</code> to 1.1.2</a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/1039">Upgrading version to 3.2.0</a></li> </ul> <h2>v3.1.0</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/939">Use <code>@âactions/core</code> <code>saveState</code> and <code>getState</code></a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/922">Add <code>github-server-url</code> input</a></li> </ul> <h2>v3.0.2</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/770">Add input <code>set-safe-directory</code></a></li> </ul> <h2>v3.0.1</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/762">Fixed an issue where checkout failed to run in container jobs due to the new git setting <code>safe.directory</code></a></li> <li><a href="https://redirect.github.com/actions/checkout/pull/744">Bumped various npm package versions</a></li> </ul> <h2>v3.0.0</h2> <ul> <li><a href="https://redirect.github.com/actions/checkout/pull/689">Update to node 16</a></li> </ul> <h2>v2.3.1</h2> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/actions/checkout/commit/c85c95e3d7251135ab7dc9ce3241c5835cc595a9"><code>c85c95e</code></a> Release v3.5.3 (<a href="https://redirect.github.com/actions/checkout/issues/1376">#1376</a>)</li> <li><a href="https://github.com/actions/checkout/commit/d106d4669b3bfcb17f11f83f98e1cab478e9f635"><code>d106d46</code></a> Add support for sparse checkouts (<a href="https://redirect.github.com/actions/checkout/issues/1369">#1369</a>)</li> <li><a href="https://github.com/actions/checkout/commit/f095bcc56b7c2baf48f3ac70d6d6782f4f553222"><code>f095bcc</code></a> Fix typos found by codespell (<a href="https://redirect.github.com/actions/checkout/issues/1287">#1287</a>)</li> <li><a href="https://github.com/actions/checkout/commit/47fbe2df0ad0e27efb67a70beac3555f192b062f"><code>47fbe2d</code></a> Fix: Checkout fail in self-hosted runners when faulty submodule are checked-i...</li> <li>See full diff in <a href="https://github.com/actions/checkout/compare/8e5e7e5ab8b370d6c329ec480221332ada57f0ab...c85c95e3d7251135ab7dc9ce3241c5835cc595a9">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/checkout&package-manager=github_actions&previous-version=3.5.2&new-version=3.5.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details>
Mock library for Dart inspired by Mockito.
Mockito 5.0.0 supports Dart's new null safety language feature in Dart 2.12, primarily with code generation.
To use Mockito‘s generated mock classes, add a build_runner
dependency in your package’s pubspec.yaml
file, under dev_dependencies
; something like build_runner: ^1.11.0
.
For alternatives to the code generation API, see the NULL_SAFETY_README.
Let's start with a Dart library, cat.dart
:
import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; // Annotation which generates the cat.mocks.dart library and the MockCat class. @GenerateNiceMocks([MockSpec<Cat>()]) import 'cat.mocks.dart'; // Real class class Cat { String sound() => "Meow"; bool eatFood(String food, {bool? hungry}) => true; Future<void> chew() async => print("Chewing..."); int walk(List<String> places) => 7; void sleep() {} void hunt(String place, String prey) {} int lives = 9; } void main() { // Create mock object. var cat = MockCat(); }
By annotating the import of a .mocks.dart
library with @GenerateNiceMocks
, you are directing Mockito's code generation to write a mock class for each “real” class listed, in a new library.
The next step is to run build_runner
in order to generate this new library:
flutter pub run build_runner build # OR dart run build_runner build
build_runner
will generate a file with a name based on the file containing the @GenerateNiceMocks
annotation. In the above cat.dart
example, we import the generated library as cat.mocks.dart
.
NOTE: by default only annotations in files under test/
are processed, if you want to add Mockito annotations in other places, you will need to add a build.yaml
file to your project, see this SO answer.
The generated mock class, MockCat
, extends Mockito's Mock class and implements the Cat class, giving us a class which supports stubbing and verifying.
// Interact with the mock object. cat.sound(); // Verify the interaction. verify(cat.sound());
Once created, the mock instance will remember all interactions. Then you can selectively verify
(or verifyInOrder
, or verifyNever
) the interactions you are interested in.
// Stub a mock method before interacting. when(cat.sound()).thenReturn("Purr"); expect(cat.sound(), "Purr"); // You can call it again. expect(cat.sound(), "Purr"); // Let's change the stub. when(cat.sound()).thenReturn("Meow"); expect(cat.sound(), "Meow"); // You can stub getters. when(cat.lives).thenReturn(9); expect(cat.lives, 9); // You can stub a method to throw. when(cat.lives).thenThrow(RangeError('Boo')); expect(() => cat.lives, throwsRangeError); // We can calculate a response at call time. var responses = ["Purr", "Meow"]; when(cat.sound()).thenAnswer((_) => responses.removeAt(0)); expect(cat.sound(), "Purr"); expect(cat.sound(), "Meow"); // We can stub a method with multiple calls that happened in a particular order. when(cat.sound()).thenReturnInOrder(["Purr", "Meow"]); expect(cat.sound(), "Purr"); expect(cat.sound(), "Meow"); expect(() => cat.sound(), throwsA(isA<StateError>()));
The when
, thenReturn
, thenAnswer
, and thenThrow
APIs provide a stubbing mechanism to override this behavior. Once stubbed, the method will always return stubbed value regardless of how many times it is called. If a method invocation matches multiple stubs, the one which was declared last will be used. It is worth noting that stubbing and verifying only works on methods of a mocked class; in this case, an instance of MockCat
must be used, not an instance of Cat
.
Using thenReturn
to return a Future
or Stream
will throw an ArgumentError
. This is because it can lead to unexpected behaviors. For example:
Future
, unexpected behavior could occur.Future
or Stream
and it doesn't get consumed in the same run loop, it might get consumed by the global exception handler instead of an exception handler the consumer applies.Instead, use thenAnswer
to stub methods that return a Future
or Stream
.
// BAD when(mock.methodThatReturnsAFuture()) .thenReturn(Future.value('Stub')); when(mock.methodThatReturnsAStream()) .thenReturn(Stream.fromIterable(['Stub'])); // GOOD when(mock.methodThatReturnsAFuture()) .thenAnswer((_) async => 'Stub'); when(mock.methodThatReturnsAStream()) .thenAnswer((_) => Stream.fromIterable(['Stub']));
If, for some reason, you desire the behavior of thenReturn
, you can return a pre-defined instance.
// Use the above method unless you're sure you want to create the Future ahead // of time. final future = Future.value('Stub'); when(mock.methodThatReturnsAFuture()).thenAnswer((_) => future);
Mockito provides the concept of the “argument matcher” (using the class ArgMatcher) to capture arguments and to track how named arguments are passed. In most cases, both plain arguments and argument matchers can be passed into mock methods:
// You can use plain arguments themselves when(cat.eatFood("fish")).thenReturn(true); // ... including collections when(cat.walk(["roof","tree"])).thenReturn(2); // ... or matchers when(cat.eatFood(argThat(startsWith("dry")))).thenReturn(false); when(cat.eatFood(any)).thenReturn(false); // ... or mix arguments with matchers when(cat.eatFood(argThat(startsWith("dry")), hungry: true)).thenReturn(true); expect(cat.eatFood("fish"), isTrue); expect(cat.walk(["roof","tree"]), equals(2)); expect(cat.eatFood("dry food"), isFalse); expect(cat.eatFood("dry food", hungry: true), isTrue); // You can also verify using an argument matcher. verify(cat.eatFood("fish")); verify(cat.walk(["roof","tree"])); verify(cat.eatFood(argThat(contains("food")))); // You can verify setters. cat.lives = 9; verify(cat.lives=9);
If an argument other than an ArgMatcher (like any
, anyNamed
, argThat
, captureThat
, etc.) is passed to a mock method, then the equals
matcher is used for argument matching. If you need more strict matching, consider using argThat(identical(arg))
.
However, note that null
cannot be used as an argument adjacent to ArgMatcher arguments, nor as an un-wrapped value passed as a named argument. For example:
verify(cat.hunt("backyard", null)); // OK: no arg matchers. verify(cat.hunt(argThat(contains("yard")), null)); // BAD: adjacent null. verify(cat.hunt(argThat(contains("yard")), argThat(isNull))); // OK: wrapped in an arg matcher. verify(cat.eatFood("Milk", hungry: null)); // BAD: null as a named argument. verify(cat.eatFood("Milk", hungry: argThat(isNull))); // BAD: null as a named argument.
Mockito currently has an awkward nuisance to its syntax: named arguments and argument matchers require more specification than you might think: you must declare the name of the argument in the argument matcher. This is because we can‘t rely on the position of a named argument, and the language doesn’t provide a mechanism to answer “Is this element being used as a named element?”
// GOOD: argument matchers include their names. when(cat.eatFood(any, hungry: anyNamed('hungry'))).thenReturn(true); when(cat.eatFood(any, hungry: argThat(isNotNull, named: 'hungry'))).thenReturn(false); when(cat.eatFood(any, hungry: captureAnyNamed('hungry'))).thenReturn(false); when(cat.eatFood(any, hungry: captureThat(isNotNull, named: 'hungry'))).thenReturn(true); // BAD: argument matchers do not include their names. when(cat.eatFood(any, hungry: any)).thenReturn(true); when(cat.eatFood(any, hungry: argThat(isNotNull))).thenReturn(false); when(cat.eatFood(any, hungry: captureAny)).thenReturn(false); when(cat.eatFood(any, hungry: captureThat(isNotNull))).thenReturn(true);
Use verify
or verifyNever
:
cat.sound(); cat.sound(); // Exact number of invocations verify(cat.sound()).called(2); // Or using matcher verify(cat.sound()).called(greaterThan(1)); // Or never called verifyNever(cat.eatFood(any));
Use verifyInOrder
:
cat.eatFood("Milk"); cat.sound(); cat.eatFood("Fish"); verifyInOrder([ cat.eatFood("Milk"), cat.sound(), cat.eatFood("Fish") ]);
Verification in order is flexible - you don't have to verify all interactions one-by-one but only those that you are interested in testing in order.
verifyZeroInteractions(cat);
cat.sound(); verify(cat.sound()); verifyNoMoreInteractions(cat);
Use the captureAny
, captureThat
, and captureAnyNamed
argument matchers:
// Simple capture cat.eatFood("Fish"); expect(verify(cat.eatFood(captureAny)).captured.single, "Fish"); // Capture multiple calls cat.eatFood("Milk"); cat.eatFood("Fish"); expect(verify(cat.eatFood(captureAny)).captured, ["Milk", "Fish"]); // Conditional capture cat.eatFood("Milk"); cat.eatFood("Fish"); expect(verify(cat.eatFood(captureThat(startsWith("F")))).captured, ["Fish"]);
Use untilCalled
:
// Waiting for a call. cat.eatFood("Fish"); await untilCalled(cat.chew()); // Completes when cat.chew() is called. // Waiting for a call that has already happened. cat.eatFood("Fish"); await untilCalled(cat.eatFood(any)); // Completes immediately.
Mockito provides two APIs for generating mocks, the @GenerateNiceMocks
annotation and the @GenerateMocks
annotation. The recommended API is @GenerateNiceMocks
. The difference between these two APIs is in the behavior of a generated mock class when a method is called and no stub could be found. For example:
void main() { var cat = MockCat(); cat.sound(); }
The Cat.sound
method returns a non-nullable String, but no stub has been made with when(cat.sound())
, so what should the code do? What is the “missing stub” behavior?
@GenerateMocks
is to throw an exception.@GenerateNiceMocks
is to return a “simple” legal value (for example, a non-null
value for a non-nullable return type). The value should not be used in any way; it is returned solely to avoid a runtime type exception.You can also write a simple fake class that implements a real class, by extending Fake. Fake allows your subclass to satisfy the implementation of your real class, without overriding the methods that aren't used in your test; the Fake class implements the default behavior of throwing UnimplementedError (which you can override in your fake class):
// Fake class class FakeCat extends Fake implements Cat { @override bool eatFood(String food, {bool? hungry}) { print('Fake eat $food'); return true; } } void main() { // Create a new fake Cat at runtime. var cat = FakeCat(); cat.eatFood("Milk"); // Prints 'Fake eat Milk'. cat.sleep(); // Throws. }
Use reset
:
// Clearing collected interactions: cat.eatFood("Fish"); clearInteractions(cat); cat.eatFood("Fish"); verify(cat.eatFood("Fish")).called(1); // Resetting stubs and collected interactions: when(cat.eatFood("Fish")).thenReturn(true); cat.eatFood("Fish"); reset(cat); when(cat.eatFood(any)).thenReturn(false); expect(cat.eatFood("Fish"), false);
Use logInvocations
and throwOnMissingStub
:
// Print all collected invocations of any mock methods of a list of mock objects: logInvocations([catOne, catTwo]); // Throw every time that a mock method is called without a stub being matched: throwOnMissingStub(cat);
Testing with real objects is preferred over testing with mocks - if you can construct a real instance for your tests, you should! If there are no calls to verify
in your test, it is a strong signal that you may not need mocks at all, though it‘s also OK to use a Mock
like a stub. When it’s not possible to use the real object, a tested implementation of a fake is the next best thing - it's more likely to behave similarly to the real class than responses stubbed out in tests. Finally an object which extends Fake
using manually overridden methods is preferred over an object which extends Mock
used as either a stub or a mock.
A class which extends Mock
should never stub out its own responses with when
in its constructor or anywhere else. Stubbed responses should be defined in the tests where they are used. For responses controlled outside of the test use @override
methods for either the entire interface, or with extends Fake
to skip some parts of the interface.
Similarly, a class which extends Mock
should never have any implementation. It should not define any @override
methods, and it should not mixin any implementations. Actual member definitions can‘t be stubbed by tests and can’t be tracked and verified by Mockito. A mix of test defined stubbed responses and mock defined overrides will lead to confusion. It is OK to define static utilities on a class which extends Mock
if it helps with code structure.
Read more information about this package in the FAQ.