top of page
Writer's picturepavithrasenthurai

TestNG Project Setup in Visual Studio Code

 

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.


 
 

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.

Click on the extension symbol, start searching for the extensions and click install on the extensions that your project requires. You can see all the installed extensions in your VS-Code as this screenshot depicts.
 

Creating a Maven Project


  1. We can create a maven project using following command from the PowerShell in windows

    1. Navigate to a folder where you like to create a maven project

    2. Right click on the folder to launch the command prompt or a PowerShell

    3. Execute the following command from the Prompt

    4. 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 .

  1. We can also create a maven project using VS-Code


    1. Launch VS-Code and follow the screenshot to create a maven project

    Method 1: Click on the + on Maven Section to create the new maven project

    Method 2: use Ctrl+Shift+P to open the command search and start typing maven


Enter the information required for maven project as shown below


Select an archetype suitable for your use case. eg: maven-archetype
Select a version for the selected archetype
Enter a group id for the maven project, which is equivalent of a company id followed by department

Enter an artifact id which can be repo or project name

You will be prompted a folder selector to pick a folder for your project

You might be able to see command prompt ran a script and wait for your confirmation, Accept the default value to continue

Select "Open Folder" from this screen or from the file menu and open the project that just created using the maven

As you see, your maven project is created with the required folder structure and you can continue contributing to the project right from this window
 

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.


Click on the gear from left bottom as shown in the image to view the menu, Select Backup and Sync Setting
Select the features which you want to backup

Select the account to backup the settings, preferably GitHub.

Browser will pop up for authentication where you can select the account you would like to sign in for.

 

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.

Click "Publish to GitHub" to share the created project in the remote server
Select the appropriate option from the suggestion and click enter to publish

Select the files which you like to share, click enter and it will notify you successfully published to GitHub

 

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

Click the Git symbol to open the source control. On second source control, click the dots(...) to open the 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.


 







bottom of page