Java program to prove Test Driven Development

264 views Asked by At

I have to write a java program, and prove that i used TDD while writing the program. I need to find some method to prove the use of Test Driven Development, meaning to somehow log the failures of some tests, then log writing of some code, then log the tests passing, and so on. Any help is welcome. Also any java related TDD documentation sources would help! Thank you!

3

There are 3 answers

1
Michael Szymczak On

Personally, I disagree that you should judge developers based on whether they used TDD or not. It’s like judging a Striker by how skilful they are in dribbling. The only thing that matters is whether they helped their team to win or scored enough goals. As with dribbling, TDD is a mean, not a destination. As it is not a goal on its own, there is no need to test whether you have used TDD while developing you app or not. You decide to use TDD if you believe that this helps you with creating a maintainable, tested and future-proof solution and this should be your goal. If you can achieve the same results using some other technique, the results should speak for themselves. Having said that, TDD is by far the most popular and proven technique to achieve above mentioned qualities. Therefore, you can test if someone skilfully used TDD (or equally efficient technique) by measuring the quality of the result. TDD is just a tool and as with any other tool, you need practice to use it properly. Poor TDD can lead to a poor design with a bunch of useless tests.

To test if someone used TDD or equally efficient process:

  • Run static analysis (such as sonar, qulice etc.) and compare the results with some reference projects (with good and bad design, as you need some benchmark). TDD provides a feedback loop that helps you deliver a well-designed software. Poor design is a clear indicator that TDD hasn't been used or the person didn't know how to use the feedback that TDD provided.
  • Run mutation tests (such as pitest) and, as above, compare the results with some reference project that is well tested and poorly tested. 100% coverage is not a TDD goal. However, one of its goals is to give you confidence to change and improve your code by providing a valuable test suite and self-documented code. The side effect of applying Three Laws of TDD is that you have very high code coverage. I encourage you to use a mutation framework, not merely a coverage analysis. Mutation tests check if the test suite actually tests the behaviour (and not merely executes lines of code to achieve high coverage).

If, according to the check above, the project has good design and is well tested, you can ask the author whether they used TDD out of curiosity, but this should not affect your judgement. On the contrary – if the design is good and the project is well tested despite not using TDD, it is an opportunity for you to discover and add new tools to your toolbox that can help you to achieve your goals as a developer.

2
bdulac On

Test Driven Development is more a kind of development methodology.

The reference book, by Kent Beck, defines TDD by example. Literally speaking, you can't prove the use of TDD. To cite the author, TDD is a sets of rules that imply "Red/green/refactor-the TDD mantra". That is to say:

  1. Red-Write a little test that doesn't work, and perhaps doesn't compile at first
  2. Green-Make the test work quickly, committing whatever sins necessary in the process
  3. Refactor-Eliminate all of the duplication created in merely getting the test to work

This would not be a prove bot only a track of your work: for the points 1 and 2 you could log the result of JUnit tests to show the sequence between red and green (assuming, on point 1, that your tests compile).

For the third point, this is about the measure of refactoring. A tool such as Sonar could give you measure of duplication. For that, the simple way is a project managed with Maven, what should help writing the JUnit tests. Usually, the project is built with a continuous integration tool such as Jenkins or Hudson.

0
fgul On

I can suggest that you should read Test-Driven Java Development - Second Edition ,written by Viktor Farcic, Alex Garcia, . It's amazing book.

  • Explore the tools and frameworks required for effective TDD development
  • Perform the Red-Green-Refactor process efficiently, the pillar around which all other TDD procedures are based
  • Master effective unit testing in isolation from the rest of your code
  • Design simple and easily maintainable code by implementing different techniques
  • Use mocking frameworks and techniques to easily write and quickly execute tests
  • Develop an application to implement behavior-driven development in conjunction with unit testing
  • Enable and disable features using feature toggles