Does Unit Tests still matter if Functional Tests i

2019-09-18 06:27发布

For a short summary:

  • Unit tests are the smaller ones that expects something to do it right in dev's view.
  • Functional tests are those that expects things are right in user's view

If Functional Tests are already satisfied, do we still need to do Unit Tests?

Most likely (let's use web development as context), this is common by using the browser to see if things are right by letting other users/people try the system/application.

Let us put out other tests like for edge cases.

1条回答
Melony?
2楼-- · 2019-09-18 06:56

Are there any metrics that you're using to determined if a functional test is "satisfied"?

I feel like it helps to have an objective measurement to create a baseline to compare types of tests, a common one is code coverage.

By identifying code coverage it's easy to compare functional tests, and unit tests, does the functional test cover the same lines of code as the unit test? If so than it is redundant.

The problem is this ignores a ton of other issues:

  • Are the functional tests prohibitively long to run? Are they difficult to setup, or are they only executed in CI? Then it may make sense to duplicate lines of code in unit tests, which will provide developers with fast feedback.
  • Is this a POC or an immature project? Functional tests may provide the best bang for the buck since they should be able to assert higher level use cases and be abstracted from implementation details. This is extremely helpful when implementation details are uncertain
  • Code coverage is misleading, An IO centric library (ie, DB driver) could easily have 100% code coverage, by mocking its dependencies. If we use code coverage to compare functional tests and unit tests in this case, we'd be missing multiple dimensions of testing, as functional tests will exercise the IO dependencies. (IMO unit testing in this case is actually a pretty small value, and gives false confidence in IO heavy code, resulting in integration bugs that are usually uncovered at later cycles in dev, where it's more expensive to fix issues
  • You touched on edge cases, functional tests will usually illustrate a couple of client flows. Exercising all the edge cases and error handling using functional tests usually tend to be a waste of resources and end up creating huge suites of difficult to maintain, slow tests
查看更多
登录 后发表回答