Question

Brief History

I am new to Automated Unit Testing and Mocking objects world; previously we used to do Unit Testing (including Integration Testing and we mistakenly referred that as Unit Testing) manually, but now we have planned to change all of that to I am pushing our organization to do Automated Unit Testing.

Problem is: I have a component for which I have written unit Tests (note: I am not using any TDD here, code is written first and then Unit Tests are written) covering each and every branch(if/ else or loops) of code. If I run the Unit tests suite it says that every method works as expected. That's good; but when I try to traverse the entire flow, I see there are many bugs( missing method) that should have been added. Is there a way to check this automatically?

Update As per the below Answers from KeithS and Schleis, it seems that I need Functional tests (or integration tests). Are there some useful links on automated functional tests? I tried it on Google but they are all showing generic results talking about manual testing.

Was it helpful?

Solution

Unit tests are just one level of the hierarchy of automated tests. Unit tests exist to verify that the code you (the developer) have actually written behaves the way you thought it should when you wrote it.

There are two caveats inherent in unit testing. First, coverage is not exercise. You may execute every line of code in your codebase via one or more unit tests, but if you do not assert, somewhere, that code which needed to do something actually did it, then as long as you don't get an exception, the test passes with or without the code doing this key thing.

Second, unit tests by definition exercise small, isolated pieces of your code (units), making sure each piece behaves the way the developer thinks it should. They don't test that these units play nicely with each other (that's an "integration" test), nor do they assert that the code, at any level, behaves the way the client thinks it should (that's an "acceptance" and/or an "end-to-end" test).

This second problem is your main issue in the case in point. You have 100% unit test coverage, but no integration testing, which would prove that the little pieces are put together the right way to do the larger job you expect. You also seem to have no automated acceptance testing, which approaches the entire program from the top down from the perspective of an end user. These are the levels of testing, which can be automated, that will identify your "missing" code based on failure to satisfy acceptance criteria.

OTHER TIPS

You want functional tests that run through all components working together. A test where you give your application an input and have it work with all the actual objects and then check your output. These tests verify that the connection between the tests work (as well as mocked methods actually exist).

Even with writing tests, you want to have the entire application run either by yourself or a QA. You will likely have missed things or not considered certain scenarios.

Licensed under: CC-BY-SA with attribution
scroll top