TestNG (Test Next Generation) is a testing framework inspired by JUnit and NUnit with its own functionalities and categories of tests such as unit, functional, end-to-end ,integration etc.
Test Configurations in TestNG allows flexible test configurations such as grouping tests, running tests in parallel, and parameterizing tests. We can validate the test results using Assertions. It is possible to approach Data-Driven Testing in TestNG to run the same test with multiple sets of data. Integration can be done easily with build tools like Maven and Gradle, and CI tools like Jenkins, Bamboo, CircleCI, Git Actions etc.
Test Driven Development (TDD) allows clear communication between developers and testers. Selenium and Java enables automation of web application tests while maintaining a readable code.
VS-Code is a light weight development tool which is easy to learn and use. To create the TestNG framework using VS-Code, we should have a knowledge of VS Code and its Git functionalities. This blog helps in understanding the Selenium TestNG TDD Project which covers the step by step process starting from setting up the repository and pushing the project to GitHub using basic commands and developing in vs code along with basic git commands.
Prerequisites | VS Code Extensions |
Installing Extensions
VS Code extensions enhances the functionality of the VS Code editor and customizes the workflow and suits the needs of the project for development and test environment. It adds new features, provides language support and integrates with external tools etc.
Creating a Maven Project
We can create a maven project using following command from the PowerShell in windows
Navigate to a folder where you like to create a maven project
Right click on the folder to launch the command prompt or a PowerShell
Execute the following command from the Prompt
Once executed get into the folder using "cd blog-testng-demo" command and execute "Code ." to launch the VS-Code
mvn archetype:generate -DgroupId="com.NumpyNinja" -DartifactId="blog-testng-demo" -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd blogTestngBDD
code .
We can also create a maven project using VS-Code
Launch VS-Code and follow the screenshot to create a maven project
Enter the information required for maven project as shown below
Backup and Sync Settings
Backup and Sync settings is crucial to maintain a consistent developing environment across various machines. It allows extensions, snippets, key bindings, UI state and other configurations to be synced through built-in setting sync feature. This feature uses your GitHub or Microsoft account to securely store the settings.
Git Functionality in VS Code
You can use the integrated Git features available in Visual Studio Code or Git commands can be executed directly from the command prompt.
Visual Studio Code Shortcuts
Shortcuts are essential and effective way to interact with the system. It helps Developers and Testers to perform the code scripts and actions quickly without clicking through the menus. It speeds up their process and enhances productivity.
Command Palette: Ctrl + Shift + P or F1 | Duplicate Line: Shift + Alt + Up/Down |
Open File: Ctrl + P | New Terminal: Ctrl + Shift + (backtick) |
Save All: Ctrl + K, S | Format Selection: Ctrl + K, Ctrl + F |
Close Editor: Ctrl + W | Format Document: Shift + Alt + F |
Close All Editors: Ctrl + K, W | Peek Definition: Alt + F12 |
Toggle Sidebar: Ctrl + B | Kill Terminal: Ctrl + Shift + K |
Toggle Terminal: Ctrl + ` (backtick) | Move Line Up/Down: Alt + Up/Down |
Go to Previous Error/Warning: Shift + F8 | Go to Next Error/Warning: F8 |
Clear Terminal: Ctrl + K | Toggle Case Sensitive in search: Alt + C |
Go to Definition: F12 | Comment/Uncomment Line: Ctrl + / |
Git Features
The features will pop up as the screenshot depicts above and you can perform the features accordingly.
Pull | To pull the latest code from the remote location of the same branch |
Push | To push all the commits from the local to remote location for the same branch |
Clone | To clone the new repo from the remote location using Git clone URL |
Checkout to | To checkout from the current branch to the newly created branch or different existing branch |
Fetch | To fetch the latest updates from the remote repo |
Commit | To commit the latest changes in your local |
Changes | To perform commands like Stage, Unstage, and Discard all changes |
Pull,Push | To pull or push from a particular branch |
It helps to perform branch related GitHub functionality | |
Remote | To add, remove remote git servers |
Stash | You can backup/restore the local changes on the local repo |
Tags | You can create/delete tags from the local repo. Tags are similar to branches, usually used during releases |
GitHub Copilot/Copilot Chat
As you see, we have installed GitHub Copilot and GitHub Copilot-chat in the VS-Code extensions. GitHub Copilot is a paid service which effectively detects the syntax and code errors and suggests the corrected ones. If you encounter an error in your code, you mouse over on the code, it will suggest you options to choose whether you can make a correction with a suggested explanation or you can just click "fix using copilot" and it will fix your errors but always confirm the solution.
GitHub Copilot Chat is a conversation space where you can raise your queries and get answers. You can also copy your complex codes or scripts and paste it in the chat to get the line by line explanation by reading your given codes.