Over a million developers have joined DZone.

The Component Test

· Agile Zone

Reduce testing time & get feedback faster through automation. Read the Benefits of Parallel Testing, brought to you in partnership with Sauce Labs.

A component test is a test that limits the scope of the exercised software to a portion of the system under test. It is in contrast to a BroadStackTest that's intended to exercise as much of the system as is reasonable.

The difference between broad-stack and component tests is one of degree rather than an absolute difference. Component tests can be as large or small as you define your components. The essence of the difference is that component tests deliberately neglect parts of the system outside the scope of the test. This is usually done by manipulating the system through internal code interfaces, using tools like xunit testing tools, and by using TestDoubles to isolate the code under test from other components.

Component tests are usually easier to write and maintain than broad-stack tests. They are also faster to run, since they only hit part of the code base. In theory a system with excellent component test coverage should be free of bugs, but in practice bugs like to lurk in the interactions between components. Therefore it's good to use the TestPyramid and combine a large quantity of component tests with a smaller amount of broad-stack tests.

The Agile Zone is brought to you in partnership with Sauce Labs. Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure.

Topics:

Published at DZone with permission of Martin Fowler , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}