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

Not possible to hit breakpoint when using Mocktail due to Dart Debugger bug #149

Open
maks opened this issue Sep 14, 2022 · 2 comments
Open
Assignees
Labels
investigating Investigating a reported issue question Further information is requested

Comments

@maks
Copy link

maks commented Sep 14, 2022

@felangel might be worth adding a note to Mocktail's Readme to warn people about this rather nasty Dart debugger bug when trying to set breakpoints as it seems to affect me using Mocktail also: dart-lang/sdk#43197 (comment)

I just ran into it myself now after an hour of head scratching trying to figure out what on earth was going on.

@felangel
Copy link
Owner

Hi @maks 👋
Thanks for opening an issue!

Are you able to provide a link to a minimal reproduction sample using mocktail? I don't think I've ever run into this issue myself 🤔

@felangel felangel self-assigned this Sep 14, 2022
@felangel felangel added question Further information is requested waiting for response Waiting for follow up labels Sep 14, 2022
@maks
Copy link
Author

maks commented Sep 14, 2022

@felangel sure thing. Its basically the same as what @DanTup has in his example:

calc.dart in your apps lib dir:

class Calculator {
  int calculate() {
    print("calculating..."); // Add a breakpoint here
    return 6 * 7;
  }
}

then in your test dir bad_test.dart:

import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:zory/calc.dart';

// With this line commented out, the breakpoint will be hit when debugging the test.
// With this line uncommented (but nothing using it), the breakpoint will not be hit.
class MockCalculator extends Mock implements Calculator {}

void main() {
  test('calculate', () async {
    expect(Calculator().calculate(), 42);
  });
}

And per the code comments, set breakpoint on line 3 print() of Calc class, run test under debug (I use the little "codelens" link in VSCode above the test function definition), breakpoint never hit.
Comment out the line in the test that defines the MockCalculator, (check that the breakpoint is still set), re-debug test and now breakpoint is hit.

@felangel felangel added investigating Investigating a reported issue and removed waiting for response Waiting for follow up labels Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigating Investigating a reported issue question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants