Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit Testing or Functional Testing? [closed]

I have recently heard of Functional Testing over Unit Testing.

I understand that Unit Testing tests each of the possibilities of a given piece of code from its most atomic form. But what about Functional Testing?

This sounds to me like only testing if the code works, but is it as reliable as Unit Testing?

I've been told there was two school of thoughts for the matter. Certains would prefer Unit Testing, others Functional Testing.

Is there any good resources, links, books, any references or one of you all who can explain and elighten my path on the subject?

Thanks!

like image 409
Will Marcouiller Avatar asked Feb 09 '10 15:02

Will Marcouiller


People also ask

What is unit testing vs functional testing?

Unit testing and Functional testing are the foundation of the testing process. The main difference is between the two is: Unit testing is performed by the developer during the development cycle, and. Functional testing is performed by the tester during the level of system testing.

Is unit testing functional or nonfunctional?

Different Types of Functional testing are Unit testing, Integration testing, Smoke testing, Usability testing, User acceptance testing, System testing, Regression testing.

Is functional testing end to end?

End to End Testing is usually executed after functional and system testing. It uses actual production like data and test environment to simulate real-time settings.

Which is better unit testing or integration testing?

While unit tests always take results from a single unit, such as a function call, integration tests may aggregate results from various parts and sources. In an integration test, there is no need to mock away parts of the application. You can replace external systems, but the application works in an integrated way.


2 Answers

Unit testing versus functional testing is not an xor, but rather an and. Unit testing is about testing units in isolation while functional testing is about testing the whole in integration (do all the units works together properly?).

Both are necessary components of good software engineering practices.

like image 181
jason Avatar answered Sep 27 '22 22:09

jason


Jason's answer is correct. Different types of tests have different purposes, and can be layered for best results (good design, meeting specifications, reduced defects).

  • Unit testing = drives design (with Test-Driven Development, or TDD)
  • Integration testing = do all the pieces work together
  • Customer acceptance testing = does it meet the customer's requirements
  • Manual testing = often covers the UI; dedicated testers can find what automation misses
  • Load testing = how well does the system perform with realistic amounts of data

There is some overlap between these categories; unit tests can specify behavior, for instance.

And there are others; for more than most people care to know, see Software Testing.

One point people missed is that unit testing is testing pieces of code in isolation. Good unit tests don't hit the database, for instance. This has two advantages: it makes the tests run fast so you'll run them more often, and it forces you to write loosely coupled classes (better design).

You asked for resources; I recommend Roy Osherove's book The Art of Unit Testing with Examples in .NET. While no book is perfect, this one gives many excellent pointers on writing good tests.

EDIT: And for writing tests against existing software, nothing beats Michael Feathers' book Working Effectively with Legacy Code.

like image 38
TrueWill Avatar answered Sep 27 '22 22:09

TrueWill