http://artofunittesting.com/definition-of-a-unit-test/
A
good unit test is:
§ Able
to be fully automated
§ Has
full control over all the pieces running (Use mocks or stubs to achieve this
isolation when needed)
§ Can
be run in any order if
part of many other tests
§ Runs
in memory (no
DB or File access, for example)
§ Consistently returns
the same result (You always run the same test, so no random numbers, for
example. save those for integration or range tests)
§ Runs fast
§ Tests
a single
logical concept in the system
§ Readable
§ Maintainable
§ Trustworthy (when
you see its result, you don’t need to debug the code just to be sure)
A test is not a unit test if:
1.It talks to the database
2.It communicates across the network
3.It touches the file system
4.It can’t run at the same time as any of your other unit tests
5.You have to do special things to your
environment (such as editing config files) to run it.
2. Unit Test Best
practice
http://www.slideshare.net/nickokiss/unit-testing-best-practices?from_search=7
3. Testable Code
Based on lots of
practices, we found the testable code is fundamental for unit test, here is a
article from Google to use.
http://misko.hevery.com/attachments/Guide-Writing%20Testable%20Code.pdf