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

Unit testing patterns #31

Open
guilhermebruzzi opened this issue Jan 17, 2020 · 4 comments
Open

Unit testing patterns #31

guilhermebruzzi opened this issue Jan 17, 2020 · 4 comments
Labels
discussion Something isn't working practices/patterns stale This will not be worked on

Comments

@guilhermebruzzi
Copy link
Contributor

What is to be discussed?

We should create a pattern to be easier to read unit testing on PRs (specially if you don't have all the context on the project), and it is difficult to solve this with linter, so it must be a guide with good practices also.

Describe the solution you'd like

Me and @klzns and most of inStore team like this pattern of arrange, act and assert to do unit testing:

https://xp123.com/articles/3a-arrange-act-assert/
https://martinfowler.com/articles/practical-test-pyramid.html#TestStructure

So instead of:

it('test', () => {
  expect(myFunction({ param1: 'string', param2: 10, param3: true})).toEqual({
    a
    long
    object...
  })
})

You reorganize to do like that:

it('test', () => {
  const params = {
    param1: 'string',
    param2: 10,
    param3: true
  }
  const expectedResult = {
    a
    long
    object...
  }

  const result = myFunction(params)

  expect(result).toEqual(expectedResult)
})

Which is easier to read.

But we can create more nice patterns about this subject in this issue, not only the way you arrange it.

@gtkatakura
Copy link
Contributor

Aligning describes based on a scenario (usually a predicate) and possible input values ​​makes it easier to see new scenarios and read test output, for example:
Screenshot from 2020-01-17 13-32-50

Code source of the example.

Some other interesting patterns from the ruby ​​community: http://betterspecs.org/

@klzns
Copy link
Contributor

klzns commented Jan 17, 2020

Some other interesting patterns from the ruby ​​community: http://betterspecs.org/

Interesting read! Thanks

@kaisermann kaisermann added discussion Something isn't working practices/patterns labels Jan 17, 2020
@guilhermebruzzi
Copy link
Contributor Author

The ruby ​​community is great at tooling and testing, very interesting stuff! :D

@stale
Copy link

stale bot commented Jan 24, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is a discussion thread, the most voted option will be final. Thank you for your contributions.

@stale stale bot added the stale This will not be worked on label Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Something isn't working practices/patterns stale This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants