Lab – 6
Aim: Using JUNIT for conducting unit test over GIT-HUB
Description:
Visual Studio Code:
Visual Studio Code, also commonly referred to as VS Code, is a source-code editor made by Microsoft with
the Electron Framework, for Windows, Linux and Mac-OS. Features include support for debugging,
syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded GIT.
Visual Studio Code features a lightning fast source code editor, perfect for day-to-day use. With
support for hundreds of languages,
VS Code helps you be instantly productive with syntax highlighting, bracket-matching, auto-
indentation, box-selection, snippets, and more.
Intuitive keyboard shortcuts, easy customization and community-contributed keyboard shortcut
mappings let you navigate your code with ease.
Customize every feature to your liking and install any number of third-party extensions.
VS Code includes enriched built-in support for Node.js development with JavaScript and Type
Script, powered by the same underlying technologies that drive Visual Studio.
VS Code also includes great tooling for web technologies such as JSX/React, HTML, CSS, SCSS,,
and JSON
Architecturally, Visual Studio Code combines the best of web, native, and language-specific
technologies.
Visual Studio Code includes a public extensibility model that lets developers build and use
extensions, and richly customize their edit-build-debug experience.
Installation of Visual Studio Code:
Step 1: Visit the official website of the Visual Studio Code using any web browser like Google
Chrome, Microsoft Edge, etc.
Step 2: Press the “Download for Windows” button on the website to start the download of the Visual
Studio Code Application.
Step 3: When the download finishes, then the Visual Studio Code icon appears in the downloads
folder.
Step 4: Click on the installer icon to start the installation process of the Visual Studio Code.
Step 5: After the Installer opens, it will ask you for accepting the terms and conditions of the Visual
Studio Code. Click on I accept the agreement and then click the Next button.
Step 6: Choose the location data for running the Visual Studio Code. It will then ask you for browsing
the location. Then click on Next button.
Step 7: Then it will ask for beginning the installing setup. Click on the Install button.
Step 8: After clicking on Install, it will take about 1 minute to install the Visual Studio Code on your
device.
Step 9: After the Installation setup for Visual Studio Code is finished, it will show a window like this
below. Tick the “Launch Visual Studio Code” checkbox and then click Next.
Step 10: After the previous step, the Visual Studio Code window opens successfully. Now you can
create a new file in the Visual Studio Code window.
Performing Unit Test using JUNIT in VS-Code:
Open Visual Studio Code editor
Select Extensions icon from left tool bar or use short cut key (Ctrl + Shift + X)
A Tab opened after tool bar displaying Extensions Installed button, Recommended button
Also text bar for searching installed extensions with filter and refresh options
Dr B.V. Rama Krishna Associate Professor (CSE)
Select “Extension Pack for Java” from recommended list
Select “Install” button to download extension pack as built in library for VS-Code
The pack includes features as
Extension pack includes
Java Language Library
Java Debugger
Test Runner for JUNIT/TestNG tool
Maven for Java
Project Manager for Java
IntelliCode-AI assisted
Testing using JUNIT:
Create a folder on desktop named "IDLE"
open explorer with IDLE folder selction
use popup window to add new file with name "Myprg.java"
enter the following code in Myprg.java
public class bvr1
{
public String pword()
{ return ("Hello");}
}
save the file
select testing tool in tool bar ...currently no testing tool associated
select enable java tests button
The installation of JUNIT package begins automatically
wait until installation finished
Now you can watch LIB folder under your directory"IDLE" with library added
junit-platform-console-standalone-1.10.0.jar
Now create a file named "MyprgTest.java" begin typing code as
Dr B.V. Rama Krishna Associate Professor (CSE)
import org.junit.*;
public class bvr1Test {
@Test
public void Test()
{
bvr1 t=new bvr1();
Assert.assertEquals("Hello", t.pword());
}
}
VSCode assists you with opening methods automatically
Select testing tool in toolbar markers appear in your MyTest.java file
Choose only Test() method block and click process begins and reports status of results
Now go to MyTest.java file and change argument value “Hello” to “Helo”
Perform testing again JUNIT detects and reports errors in code as follows
Dr B.V. Rama Krishna Associate Professor (CSE)
Generating Test failed report at console.
Similarly we can check any java project module in this environment effectively.
Dr B.V. Rama Krishna Associate Professor (CSE)