Software Testing Lab
Software Testing Lab
import javax.swing.*;
/**
*
* @author moizk
*/
public class Midlabq2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
char[][][] array = {{{' ', '', ' ', ' ', ' ', ' ', ' ', ' ', '', ' '},
{' ', '', '', ' ', ' ', ' ', ' ', ' ', '*', ' '},
{'#', '', ' ', '', ' ', ' ', ' ', '', '', '#'},
{' ', '', ' ', ' ', '', ' ', '', ' ', '', ' '},
{' ', '', ' ', ' ', ' ', '', ' ', ' ', '*', ' '},
{'#', '', ' ', ' ', ' ', ' ', ' ', ' ', '', '#'}}};
int i = 0;
do{
do{
int j= 0;
do{
System.out.print(array[0][i][j]);
j++;
}while(j<array[0][i].length);
System.out.println();
i++;
}while(i<array[0].length);
}while(false);
}
}
---------------------------------------------------------------------------------------------------------
Main Java Class
package com.example;
// Testing addition
int sum = calculator.add(5, 3);
System.out.println("5 + 3 = " + sum); // Expected output: 8
// Testing subtraction
int difference = calculator.subtract(10, 4);
System.out.println("10 - 4 = " + difference); // Expected output: 6
}
}
=====================================
Other Java Calculator Class
package softtst;
/**
*
* @author Usman Ali
*/
public class Calculator {
}
==================================
Junit Test Class
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java
to edit this template
*/
package softtst;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author Usman Ali
*/
public class CalculatorTest {
private Calculator calculator; // Declare Calculator instance
public CalculatorTest() {
}
@Before
public void setUp() {
System.out.println("Running @Before - Executes before each test case");
calculator = new Calculator(); // Initialize calculator before each test
}
@After
public void tearDown() {
System.out.println("Running @After - Executes after each test case");
}
/**
* Test of add method, of class Calculator.
*/
@Test
public void testAdd() {
System.out.println("Testing add method");
int a = 5;
int b = 3;
int expResult = 8;
int result = calculator.add(a, b);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
}
/**
* Test of subtract method, of class Calculator.
*/
@Test
public void testSubtract() {
System.out.println("Testing subtract method");
int a = 10;
int b = 4;
int expResult = 6;
int result = calculator.subtract(a, b);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
import javax.swing.*;
import java.awt.*;
frame.add(new JScrollPane(textArea));
frame.setVisible(true);
}
}