nus-cs2103-AY2021S2 / forum

10 stars 0 forks source link

Unit testing vs Integration testing #221

Open w2vgd opened 3 years ago

w2vgd commented 3 years ago

Hi, I realized that in the original AB3 code, when testing the Person class in PersonTest, the code uses PersonBuilder which in turn uses all of the attribute classes such as Name and Phone to build the Person object. So in this case, is PersonTest a form of integration testing? If it is, why is it tested using integration testing instead of unit testing in this case?

Another follow up question is when do we know if a class should be tested using unit testing (isolated from other class and only uses stubs if necessary) or integration testing?

damithc commented 3 years ago

While keeping the door open for others' comments about this specific situation, here are some general thoughts:

When writing test cases for something, decisions to make include:

Factors to consider include:

As usual, it requires a judgement call for each specific situation. If the code has dependencies, it is more common to use a hybrid approach rather than pure unit and integration testing.

ong6 commented 3 years ago

Regarding the second part of your question, I think it is heavily dependent on what you're comfortable with. If you feel like there may be changes to some essential part of the code down the line, unit testing is definitely a better choice as it won't be too dependent on other parts of the code working. However, if you feel like you're close to completion, integration testing could be a good sanity check to see if different modules of your product are working.