ruby on rails - Integration test best practices -


i looked in stackoverflow , fine one or two questions have similar title one, none of answers i'm asking. sorry if duplicated.

in unity tests, there guideline says "one assertion per test". reading around stackoverflow , internet, commonly accepted rule can relaxed bit, every unit test should test 1 aspect of code, or 1 behavior. works because when test fails can see failed , fixing test not fail again in other point in future.

this works rails unit tests, , have been using functional testing without problem. when comes integration tests, implicit should have many assertions in tests. apart that, repeat tests done once in functional , in unit tests.

so, considered practices when writing integration tests in these 2 factors:

  1. length of integration tests: how measure when integration test should splited in two? number of requests? or larger better
  2. number of assertions on integration tests: should repeat assertions presented on unit tests , functional tests current state of system every time, or should have 5 or asserts on end test if correct output generated?

hopefully provide more authoritative answer, understanding integration test should built around specific feature. example, in online store, might write 1 integration test make sure it's possible add items cart, , integration test make sure it's possible check out.

how long should integration test be?

as long takes cover feature, , no more. features small, large, , size matter of taste. when they're big, can decomposed several logical sub-features. when they're small, integration tests view or controller tests.

how many assertions should have?

as few possible, while still being useful. true of tests, goes doubly integration tests because they're slow. means testing things important, , trying not test things implied other data. in case of checkout feature, might assert order created right person , has right total, leave exact items untested (since architecture might generate total items). wouldn't make assertions before that didn't have to, since traversing application—filling field, clicking button, waiting modal open—covers integration behavior need tested, , else covered view tests if need tested @ all.

all together, in general means whereas unit tests tend couple lines long , preceded larger setup block, rails integration tests tend dozen lines long or more (most of interaction), , lack setup block entirely.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -