When should you do a code review?

Should the code review be done before or after unit testing


I discuss with my colleague when to do a code review - before or after unit testing. What's the best course of action?

Some factors we may need to consider (there may be more):

  • Code Change Size - A large change means that the code review will result in further changes. If these changes are larger than if the UT was before the code review, you'll need to redo most of your UTs again.
  • Time required to carry out the unit test
  • Is it a new feature or a bug fix?

Reply:


You should always do a unit test, before You perform the code review. Here's why

  1. If your code gets corrupted in a way that unit tests detect, you are wasting the other developer's time by including them in the red / green / refactor cycle.
  2. Tests show other developers the intended use of the code, which makes it easier to review.
  3. Tests should be reviewed along with the tested code in case test cases are missing or your tests are not working properly.
  4. Testing and code reviews tend to identify different problems, with little overlap between the problems found. Unit testing doesn't fret about having to retest code if the reviewer finds problems. Developers get annoyed and likely won't do as well on it the second time.

There are probably other reasons, but these are the ones I've personally seen and experienced implementing code review practices across 3 different teams / companies.

To edit That above What has been said applies of course for times when the code review is a step in your software development process (whether waterfall or agile). If you're working on a particularly large or difficult section of code, there is always another pair of eyes to look at.


Code reviews apply in the event that the code is "done".

In my organization, our definition of "done" includes unit tests (as we aim for TDD), so code reviews contain complete code - and complete code contains tests.

Tests also need to be reviewed and refactored to make sense for them to be part of the code review.






Tests should be viewed as part of the code to be checked. Hence, it makes sense to check after completing the tests.

Make sure that the tests are also checked. This is important for those who are new to unit testing.

Make sure your team is underestimating dependency injection, isolation frameworks, mocks versus stubs, seams, interaction versus state-based testing, and integration versus unit testing.

You don't need to implement the above topics, but you should understand them.


Well,

It depends on what you mean by "Unit Test" ...

If it is a TDD style unit test, then it is meaningless because you are writing a test while you are writing your code. There is no later case. In this case you continuously improve the code quality: Refactoring ...

AND

If it was a classic "unit test" [whatever it means, I don't know, but I mean test after you've written the code and usually done it by other people] then the main criterion is what you get from code review and expect type of unit tests: if you want a quick review of feedback and want to take action and don't have an automated unit test, then you need to wait for the unit test. If you want to identify mature code review problems and gradually apply the solution over the next iterations, you can do so before unit test ...

But is personal for a code review after or after a unit test not a real criterion for me ...

Why do we do code reviews? For code quality ... Instead of a "quality control" gate, you should bring quality into the environment of your software development process ...



Rather, I'd say let's be "agile" ... don't wait for the code to finish for a quick, informal code review: there are developers out there with whom you can actually wait for the whole code to work and topics + The test phase must be over ... but

When it comes to really new topics (brand new feature, almost researched, something completely new for the team), code review early on, don't waste any time: let someone take a look from time to time: Isolation is an important factor of failure in this case.

If the developer is new to the team as well, review the code early and possibly often .

By the way, unit tests also need to be checked.

We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.

By continuing, you consent to our use of cookies and other tracking technologies and affirm you're at least 16 years old or have consent from a parent or guardian.

You can read details in our Cookie policy and Privacy policy.