The biggest problem I encountered while using TDD is developers who are not sure about unit testing. Poor unit testing spends more time than it saves. Baffled, unreliable, inconspicuous, unreadable tests fall on the sidelines very quickly, and foggy bug developers take time to want a unit test again.
Per Fagrell makes some good points, especially about testing after each change; it should be second nature for testing before and after any change to the test.
Frames:
Consider QUnit as your framework for testing JS: http://docs.jquery.com/Qunit
I have a dependent-labeled test harness page, and the tests run very well when the page loads.
You can follow
flow for unit tests using QUnit.
However, you will have to manually use the test setup and deletion methods and name them in your test methods. This will help isolate test cases by preserving indentical conditions for all tests and not allowing tests to be dependent on their order of operation.
Look for useful frameworks in other languages ββthat you will use. NUnit is very popular for .NET.
Insulation:
Per Fagrell also draws a good conclusion about isolation. The difference between unit testing (testing one aspect of an atom of functionality) and integration (testing the interaction of several atoms) must be carefully understood before testing. If you have several statements in the test method, you are not unit testing and you need to change your test method.
Legend:
Good naming convention with excellent The Art Of Unit Testing for your MethodUnderTest_Condition_ExpectedBehaviour tests, e.g.
Expand_TextVariable_ExpandsText
Save your tests from the same book :
Otherwise, you and other developers will not want to run tests.
Fakes:
A common misunderstanding is the difference between the two types of fakes: stubs and mocks .
A seam is created in code by abstracting the functionality that the code in the interface depends on. For instance. The controller is independent of a specific repository, it will depend on an IRepository.
A stub , then implements this IRepository and returns fake values; it is used to isolate controller code that runs in isolation. for example GetCustomer() will create a new customer and return it, without GetCustomer() calls to the real repository or to any store. Workpieces are never checked for .
mock is like a stub except that it may contain values ββthat can be tested. for example AddCustomer(Customer customerToBeAdded) , your layout will accept this value and may be opposed. Cats can be tested against .
Look at the test isolation structure (or Mocking Framework), which can automatically create fakes for this interface.
Failure to understand the purpose of bullying led to the fact that more than one developer, whom I saw, create a layout for testing functionality, and then record tests against the layouts themselves.
Resources
I mentioned The Art Of Unit Testing and I recommend it completely. This is one of the books along with Code Complete that I would grab if the office caught fire.
Hope this helps.