What is TDD (Test Driven Development)? | How to do TDD with Example

🚀 What is TDD?

🚀 What are the main benefits of TDD?

Example fo TDD

package com.thetestingacademy;import static com.thetestingacademy.App.isValidUserName;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.thetestingacademy.App.*;
import org.junit.Test;
/**
* Unit test for simple App.
*/
public class AppTest
{
/**
* Rigorous Test :-)
*/
@Test
public void shouldAnswerWithTrue() {
String userName = "PramodDutta";
String userName1 = "Pramod Dutta";
String userName2 = "Pramod@123";
String userName3 = "Pramod_Dutta";
String userName4 = "Pramod/Dutta";
String userName5 = "Pramod#Dutta";
assertTrue(isValidUserName(userName));
assertFalse(isValidUserName(userName1));
assertFalse(isValidUserName(userName2));
assertFalse(isValidUserName(userName3));
assertFalse(isValidUserName(userName4));
assertFalse(isValidUserName(userName5));
}
}
package com.thetestingacademy;/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
String userName = "PramodDutta";
String userName1 = "Pramod Dutta";
isValidUserName(userName);
// What is Valid UserName
}
static boolean isValidUserName(String name){
if(name.contains("/") || name.contains("#") || name.contains(" ") || name.contains("@") || name.contains("_")){
return false;
}
return true;
}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store