0% found this document useful (0 votes)
12 views5 pages

Sumit Ex-4b

ff

Uploaded by

mdkhalid8527
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views5 pages

Sumit Ex-4b

ff

Uploaded by

mdkhalid8527
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Name: - Md Khalid Roll no.

- 11222584 BCSE-702L (Software Craftsmanship Lab)

EXPERIMENT- 4(B)
AIM: JUnit or a similar testing framework.

JUnit Testing Example :


Now, let’s consider a practical example to understand Java Junit testing. This
example, will conduct a simple test using JUnit where:
• First assign some value to a string, and
• Then with the help of the assert keyword, checking if the value assigned
matches our intended value.
Prerequisite
1. You must have Java jdk installed on your system. To check if Java is
installed on your system run the command java –version in the
Command prompt. If it is installed, it will display the Java version.
2. Any IDE of your choice. In this example, using Eclipse 2024.
Step 1: Create a Maven project
To create a Maven project, open Eclipse and then complete the following steps:
a. Click on File option
b. Hover on the New drop-down menu
c. Click on the Project option
d. Select the Maven project option
Name: - Md Khalid Roll no.- 11222584 BCSE-702L (Software Craftsmanship Lab)

e. Enter the Group id and Artifact id of your choice and proceed.


f. Your Maven project is created.

Step 2: Add Maven dependencies


In this step, you have to add some dependencies that will help in achieving
JUnit testing. Add JUnit dependency from the Maven marketplace by inserting
the dependency in the pom.xml file that you got on our Maven project.
Add this script inside the dependencies tag in the pom.xml file.
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
Name: - Md Khalid Roll no.- 11222584 BCSE-702L (Software Craftsmanship Lab)

Step 3: Create a new class file


Now create a new class file where you will write our Junit test. To do so, follow
the following steps to create a new class file.
a. Right-click on the folder src/test/java
b. Hover over to new
c. Click on the class and create a file by entering a name of your choice

Step 4: Writing the Test Script


Now the final part is to write the JUnit test after setting up the project. Open
the previously created test class file inside the src/test/java folder.
import org.junit. Test;
import org.junit. Ignore;
import static org.junit.Assert.assertEquals;

public class BrowserStackJunit {


String message = "BrowserStack is the intended message";
@Test
public void testMessage() {
System.out. println("Inside testMessage()");
Name: - Md Khalid Roll no.- 11222584 BCSE-702L (Software Craftsmanship Lab)

assertEquals(message, "BrowserStack is the intended message");


}

Step 5: Executing JUnit test


Once the test is written, right-click and then select run as JUnit test.

Once the test is executed, on successful completion of the test it will be


indicated on the left panel highlighted with green color.

Upon making any slight change in the test script that fails our test, it will be
indicated with red color and the log of error will be displayed on the console.
Name: - Md Khalid Roll no.- 11222584 BCSE-702L (Software Craftsmanship Lab)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy