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

Detect "Mockery" anti-pattern #393

Closed
h1alexbel opened this issue Jul 9, 2024 · 11 comments · Fixed by #395
Closed

Detect "Mockery" anti-pattern #393

h1alexbel opened this issue Jul 9, 2024 · 11 comments · Fixed by #395
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@h1alexbel
Copy link
Contributor

h1alexbel commented Jul 9, 2024

How about to detect Mockery anti-pattern?

Mockery definition:
Sometimes mocking can be good, and handy. But sometimes developers can lose themselves in their effort to mock out what isn’t being tested. In this case, a unit test contains so many mocks, stubs, and/or fakes that the system under test isn’t even being tested at all, instead data returned from mocks is what is being tested.

Example:

import org.mockito.Mockito;

final class FooTest {

  @Test
  void testsSomething() {
    Frame frame = Mockito.mock(Frame.class);
    Mockito.doReturn(...).when(frame).iterator();
    Table table = Mockito.mock(Table.class);
    Mockito.doReturn(frame).when(table).frame();
    Region region = Mockito.mock(Region.class);
    Mockito.doReturn(table).when(region).table(Mockito.anyString());
 }
}

in pom.xml we can introduce new parameter maxNumberOfMocks:

<configuration>
  <maxNumberOfMocks>2</maxNumberOfMocks>
</configuration>

Thus, using example above, jtcop should fail with message like this:

[ERROR]: FooTest.java#testsSomething has too many mocks: 3 (max allowed 2)
@h1alexbel
Copy link
Contributor Author

@volodya-lombrozo what do you think?

@volodya-lombrozo
Copy link
Owner

volodya-lombrozo commented Jul 9, 2024

@h1alexbel I like this idea! We can implement it. However, it's better to check if somebody already implemented something similar inside other linters. Have you checked?

@volodya-lombrozo volodya-lombrozo added enhancement New feature or request good first issue Good for newcomers labels Jul 9, 2024
@h1alexbel
Copy link
Contributor Author

@volodya-lombrozo not yet, but I can take research this topic

@h1alexbel
Copy link
Contributor Author

h1alexbel commented Jul 9, 2024

@volodya-lombrozo assign me, please

@volodya-lombrozo
Copy link
Owner

@h1alexbel Thank you!

h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
h1alexbel added a commit to h1alexbel/jtcop that referenced this issue Jul 11, 2024
@0pdd
Copy link
Collaborator

0pdd commented Jul 12, 2024

@h1alexbel 3 puzzles #396, #397, #398 are still not solved.

@0pdd
Copy link
Collaborator

0pdd commented Jul 17, 2024

@h1alexbel 2 puzzles #396, #397 are still not solved; solved: #398.

@0pdd
Copy link
Collaborator

0pdd commented Jul 29, 2024

@h1alexbel the puzzle #397 is still not solved; solved: #396, #398.

@volodya-lombrozo
Copy link
Owner

@rultor release, tag is 1.3.0, title is 1.3.0.

@rultor
Copy link
Collaborator

rultor commented Jul 29, 2024

@rultor release, tag is 1.3.0, title is 1.3.0.

@volodya-lombrozo OK, I will release it now. Please check the progress here

@rultor
Copy link
Collaborator

rultor commented Jul 29, 2024

@rultor release, tag is 1.3.0, title is 1.3.0.

@volodya-lombrozo Done! FYI, the full log is here (took me 6min)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants