Test Strategy Process(TDD&BDD)
In this article, we will examine the importance and advantages of testing strategies. We will see how important choosing a testing strategy is for a project. And we’ll go into the details of the two big test strategies.
The main purpose of software tests; is that the software is free of bugs. It performs the expected functions. Software tests also positively contribute to projects staying within the expected budget and time. That’s why software tests need to be applied correctly to projects. The most useful software test for the project is a test strategy that is chosen correctly and applied correctly.
Brief description of the testing strategy; It is the definition of how the test objectives will be achieved and which tests will be performed at which level according to the characteristics of the software to be developed to achieve these objectives. In a good testing strategy, processes should be well evaluated. Important and error-prone parts of the project should be worded carefully. And the definitions made should be clear. Some mistakes are made in determining the testing strategy. One of the most common mistakes is trying to apply the same testing strategy to every project. Each project has its characteristics, needs, and expectations. This is a natural feature of projects. Therefore, a successful test strategy in one project may not be as successful in another. In order not to cause this error, the projects should be analyzed well.
Another important mistake in determining the test strategy is that the test strategy suitable for all levels cannot be determined. If this situation exists in a project, all test cases developed in each level test are run and the results of all of them are tried to be seen. However, successful software can be delivered with a flexible and effective test strategy in a project that is in trouble in terms of time and effort. Such a situation can be overcome by prioritizing and/or grading test cases and test scenarios within the test strategy. The remaining time and effort are used effectively.
We’ll briefly review the two most important testing strategies and check for key differences between them.
What is TDD?
Test-driven development is a testing strategy implemented by writing Unit Tests to test code and separate dependencies from code. The most important step of this strategy is to write the tests before the code is written.
According to the requirements, the developer writes a test case. These tests are performed and are expected to fail because they are written before a feature is developed. Re-coding is done to pass the test successfully. It is ensured that all tests are successful. The code is reviewed and edited, and improvements are made if necessary. The process of editing the code should not change the main function of the code. It only performs the process of improving or cleaning the code without changing the behavior of the code. This replacement and editing continue until the code receives no errors.
- Write Test
- Test Fails
- Write Code
- Test Passes
- Refactor
For the developer, this process means that before a particular algorithm can be written to solve a problem, the code must be analyzed and its behavior must be known. It means that when writing a test with this process, a function will pass some conditions: its output.
In what situations would it be appropriate to choose this path?
Choosing projects where the software process has started may not be appropriate. Moving forward with TDD intent can be tricky.
The test engineer should have software experience. Because in this strategy, coding knowledge is needed for the test engineer as well as the software developer.
It can be preferred in projects whose architecture may change later. If there is such a possibility, it is a strategy that will help facilitate processes.
What is BDD?
Behavior Driven Development (BDD) is a derivative of TDD. Mainly based on system behavior.
While TDD asserts some conditions, BDD is written in plain text using real-time examples of real requirements to explain the behavior of the system. This way, you will ensure that up-to-date application documentation is created with these written texts.
Commands such as “Given”, “When”, and “Then” are used for test scenarios.
As an example;
- Given: Initial State
- When: Action takes place
- Then: Expected Outcome
For example;
Case 1
Given: The Name field is entered correctly on the login form
When: Click the Login button
Then: A warning message should be displayed for the Surname
Case 2
Given: The Name and Surname fields are entered correctly on the login page
When: Click the Login button
Then: Successfully logged in
Helps reach a wider audience with the use of spoken language. You move to a different level of abstraction than usual when describing the behavior of the software. It facilitates communication between software developers, testers and analysts, and administrators. Acceptance criteria can be created before development. Some tools based on the BDD framework are used to write acceptance tests for practice.
The most well-known of these is Cucumber. Cucumber is easily readable and understandable. Cucumber can also be used with Selenium. Along with Java language, it supports many other languages such as Perl, PHP, Python, and .Net.
In what situations would it be appropriate to choose this path?
This strategy can be chosen if the test engineer has no software experience.
It can be selected if the test process communication between different units will be provided directly. Since test cases are written in spoken language, it is the strategy that makes communication the easiest.
Test Senaryoları yazılım bilgisi olmayan kişiler tarafından hazırlanacaksa bu stratejinin seçilmesi uygun olabilir.
What are the Advantages?
What are the Advantages of TDD?
- Reduces the maintenance burden
- Errors are easily visible
- Better designs can be realized
- When the code is written, it is testable
- The code is easy to understand as it is driven by tests
- Makes it easy to change the architecture of the application
What are the advantages of BDD?
- Test scenarios are written in spoken language, so they are easy to understand
- Increases and develops cooperation
- As test scenarios are created and put into code through the user stories determined for the customer’s needs, the identified needs are better met
- It is easier to implement and learn as it is not a technical strategy
Which one is the best?
If you’re looking for the answer to this question, you haven’t thoroughly studied this article. But I’ll still tell you which strategy is better.
One way to find the correct answer to this question is;
Get to know your project
Get accurate information about testing strategies
Choose a strategy that fits the project