I have been asked to write test cases in the TDD style. I have no experience about writing TDD test cases. I have read about TDD and in essence it talks about defining test cases prior to code and then the code must pass the preceding test cases. What are the best practices to implement TDD? What approach and tools befit TDD? Can I achieve TDD using JMeter?
No. jmeter is used for performance testing.
To do TDD and BDD you need to learn how to write tests that call system components. Some will be backend for internal code quality, some will be front end which will also test actual user product functionality.
You could probably twist jmeter to achieve TDD but you would be making it very very hard. If you are new to TDD you would likely make a horrific tangled mess that is neither maintainable or extendable.
Just focus on:
- Write a failing test in the same language as the application (not required but helps a lot usually)
- Write the application code to make the test pass
- Refactor the code to be maintainable
Read some more books on applying TDD and BDD with specific examples in a language of your choice and don't even think about jmeter until you are looking at performance of many users with working application functionality that was already achieved through TDD.
This is not very applicable to JMeter as it assumes testing existing application and in the majority of cases performance testing is an ad-hoc process targeting identifying performance bottlenecks so there is nothing you can do using TDD approach here.
If you're using JMeter for functional testing you can consider the following options:
- Ruby DSL for JMeter
- There is a possibility to either execute existing .jmx test scripts or create new ones on the fly using JMeter API in Java or other language which can be run in JVM (Scala, Kotlin, Groovy, etc). See Five Ways To Launch a JMeter Test without Using the JMeter GUI for example implementation.
If you want to use performance tests in your CI/CD pipeline you can consider running your JMeter scripts in Jenkins and use Performance Plugin to visualize results and mark build as unstable/failed if performance will be worse than specified threshold. However it is more suitable for regression testing rather than for TDD