Coder Social home page Coder Social logo

Comments (6)

ochafik avatar ochafik commented on July 2, 2024

cc/ @JeromeA

from mockito.

ochafik avatar ochafik commented on July 2, 2024

Not sure, but could be the same bug as #45

from mockito.

TedSander avatar TedSander commented on July 2, 2024

So the invalid assumption here is that when you ask for a capture you will do a verify in the test. The first test does not do a verify, and so the capture state isn't reset.

Let me see if we can reset the capture state on the captureAny call. I'll also look into throwing an error if you don't do a verify when you asked for a capture, but I think that would be harder and maybe less developer friendly. There are competing ideas that mocks should error more and not be so lenient.

I'm not sure if we want to have the teardown function. Most of the time you shouldn't need it.

from mockito.

ochafik avatar ochafik commented on July 2, 2024

So actually the real core issue is mockito captures are extremely non-picky / broken: they just confuse captures between mock instances, even on different classes, even with methods of different names.

Repro:

import 'package:mockito/mockito.dart';
import 'package:test/test.dart';

class Foo1 {
  foo1(x) {}
}
class Foo2 {
  foo2(x) {}
}
class MockFoo1 extends Mock implements Foo1 {}
class MockFoo2 extends Mock implements Foo2 {}

main() {
  MockFoo1 foo1;
  MockFoo2 foo2;

  setUp(() {
    foo1 = new MockFoo1();
    foo2 = new MockFoo2();
    when(foo1.foo1(captureAny)).thenAnswer((i) => null);
    when(foo2.foo2(captureAny)).thenAnswer((i) => null);
  });

  test('wrong target', () {
    foo1.foo1(1);
    foo2.foo2(2);
    expect(verify(foo1.foo1(any)).captured, [1]); // Fails: actually gets [1, 2]
    expect(verify(foo2.foo2(any)).captured, [2]); // Fails: actually gets []
  });
}

from mockito.

srawlins avatar srawlins commented on July 2, 2024

Haha ahh! That is super broken. I think resetMockitoState is actually going to be public. It has real use cases. So that can go into your teardown.

However the other issue you raise about captures is super bad.

from mockito.

srawlins avatar srawlins commented on July 2, 2024

The above comment is correct. resetMockitoState is exported by package:mockito/mockito.dart, and in fact, it is used in each of Mockito's own tests' tearDown.

from mockito.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.