You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2019/09/05 05:36:16 UTC
[GitHub] [helix] jiajunwang edited a comment on issue #443: Implement the
WAGED rebalancer with the limited functionality.
jiajunwang edited a comment on issue #443: Implement the WAGED rebalancer with the limited functionality.
URL: https://github.com/apache/helix/pull/443#issuecomment-528203897
> > > > > Will you wait for my algorithm implementation part to be checked in? I don't think creating a mock class is necessary
> > > >
> > > >
> > > > This mock class is for unit test. Even after your code is ready, I will keep it for the test purpose. Integration test will be done in a different style. We will include real components and turn on a ZK server for that.
> > >
> > >
> > > It's strange for the unit test, you can simply use mockito.mock and mock any behavior without a real working class. A real working class is painful when future developers found the unit test is broken and he needs to understand what's going on inside the unit test helper. I would try avoiding such complicate coupled pattern in unit test as much as possible.
> > > It makes sense if you want to have such a class for integration test
> >
> >
> > Did you mean if the test breaks, people won't need to understand the mockito class and the mocked methods definition for debugging? I don't think so. Actually, since the mock classes are not returning static maps or lists, we will need to keep the logic. So even they are mockito classes, I will need to "implement" the method using the same code. Given this, making them mockito classes is not a good option from my point of view.
>
> During any refactor works, the unit test could fail. If you're testing method A, it depends on dependency class B, do you want to mock object and control all behaviors of B or use a concrete
> B instance? If the test of method A fails, do you know is it because of the wrong implementations of B or your method has flaws? Adding a custom mock will certainly increase the complexity and break the "unit test" concept which means isolated test, regardless of dependencies.
>
> An example:
>
> ```
> public void testMethodA() {
> Service service = new Servcie(new MockB()) // MockB is a custom mock class you may or may not understand how it is implemented
> boolean result = service.doSomething();
> }
>
> public void testMethodA() {
> B mock = Mockito.mock(B.class);
> when(mock.runSomehing()).thenDoSomething(); // since B is a mockito mock, its behavior is totally under control by this test metho without understanding how B internally runs
> Service service = new Service(mock);
> boolean result = service.doSomething();
> }
> ```
In the example you mentioned, mock class or mockito class look exactly the same to me. Because the code in service.doSomething() and the code in when(mock.runSomehing()).thenDoSomething() will be exactly the same. In the 2nd case, you are just wrapping the code with when(...).thenDoSomething(). If the mockito thenDoSomething() method was done in the wrong way, the dev who is doing the refactor need to check mockito method the same, right? Mockito is not magic.
High-levelly speaking, a dev needs to understand test logic. It is not an option. And the mock class here is considered to be part of the test case. Note the mock class files were in the test path. There is no way to get confused with a real class for production.
Moreover, anyone who can understand the mockito class will be able to understand the mock class.
So I don't think what you said make sense.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org