-
Notifications
You must be signed in to change notification settings - Fork 0
Test Driven Development
Requirements:
- JUNIT 5 library
- Eclipse IDE 2018 -12 64bit
- JEE Perspective
- Java 8 SDK
Git Reference URL https://github.com/schadal/JavaConcepts/tree/master/TddJava
About TDD
- Is there since 2003.
- TDD is a practice that comes from XP and agile manifesto.
- It is practice for developing quality code.
What is TDD? For this, we need java and eclipse setup. TDD is nothing but tests driving the code. It is a 3 step process in which we have red, green and blue color representation. With red color representing the code fails, green color represents functionality written to pass the test and finally blue color for refactoring the code.
TDD Rules
- Test should be written for expected outcome of the function.
- Do not judge the design. Tests should drive the design.
- Write minimum code to pass the test. Could be simple static code test.
- Each test case should validate one and only piece of business logic.
What is Integration Test:
- Integration Testing is integral part of agile development. Where we would like all changes or enhancements to the code after unit testing are continuously integrated into one piece of code and tested.
Stub Based Testing
The stub based testing is important to test the functionality without real connection to the service. See the diagram - 
Understanding Mocks, Stubs, Spy, Tautologies using Mockito for Testing Tautology: Make sure not to write any code implementation otherwords logic in any test case. Each test case should tackle one use case. The more the test cases the better it is...for example. To validate prime numbers we need atleast 2 cases - first to validate prime numbers and next to validate non-prime numbers.
What is SPY? spy is a mechanism built into Mockito that tells the mockito classes not to run underlying method implementations but to return the given value. It is very helpful when the variables are privately defined within the scope of a method and there is no way for the developer to override the functionality. Ex: @Spy (class variable) doReturn(value).when(class).method();