dart-lang / mockito

Mockito-inspired mock library for Dart
https://pub.dev/packages/mockito
Apache License 2.0
623 stars 160 forks source link

Why is build_runner is succeeding with 0 outputs? #733

Closed sethmfuller closed 5 months ago

sethmfuller commented 5 months ago

I have a simple Dart class that is using the package Dio in one of its methods. In the class's corresponding test file, I'm trying to mock Dio by placing @GenerateMocks([Dio]) above the main method. I then ran dart run build_runner build to generate the mocks for Dio. But no mocks were generated. The command line outputted the following:

[INFO] Generating build script completed, took 143ms
[INFO] Reading cached asset graph completed, took 53ms
[INFO] Checking for updates since last build completed, took 628ms
[INFO] Running build completed, took 3ms
[INFO] Caching finalized dependency graph completed, took 41ms
[INFO] Succeeded after 48ms with 0 outputs (0 actions)

Why is it not generating anything?

I tried updating my dependencies thinking that maybe this was the issue but it wasn't.

test: ^1.24.9
mockito: ^5.4.4
build_runner: ^2.4.8

I've run dart run build_runner build from the root of the project, and I get 0 outputs. I've also run it from the folder where the test is located and that errored out.

I've also tried generating mocks for a different class, but that had the exact same result.

Any ideas for what build_runner isn't generating anything?

srawlins commented 5 months ago

Can you say where the test file is located, relative to the package root? I believe it must be in test/.

sethmfuller commented 5 months ago

Can you say where the test file is located, relative to the package root? I believe it must be in test/.

Yes, @srawlins it is in the test directory. It's in the same relative directory as lib is

sethmfuller commented 5 months ago

I found the issue. It was because I had my tests in the tests/ directory instead of the test/ directory. The code generator won't find the tests if they aren't in the test/ directory. 🤦🏼‍♂️