Is it possible to test the main method in Java?
For example, I have a little program.
public class Number {
public static int add(int zahl1, int zahl2) {
return zahl1 + zahl2;
}
public static void main(String[] args) {
int numberOne;
int numberTwo;
int total;
int difference;
int product;
int quotient;
int rest;
Scanner input;
input = new Scanner(System.in);
input.useDelimiter(System.lineSeparator());
System.out.println("First Number: ");
numberOne = tastatur.nextInt();
System.out.println("Second Number: ");
NumberTwo = tastatur.nextInt();
System.out.println("Thanks for the numbers");
total = add(numberOne,numberTwo);
System.out.println("The total of " + numberOne + " and " + numberTwo
+ " is " + total);
difference = numberOne - numberTwo;
product = numberOne * numberTwo;
quotient = numberOne / numberTwo;
rest = numberOne % numberTwo;
System.out.println(differenz);
System.out.println(product);
System.out.println(quotient + "rest: " + rest );
}
}
My Test class :
public class RechenprogrammTest {
@Test
public void test() {
int numberOne = 4;
int numberTwo = 5;
int total = Number.add(numberOne, numberTwo);
assertEquals(9, total);
}
}
Is there only one way that I have to make for difference, product, quotient, and rest the same method as add or can I test the main method as I tested the add method?
I did not try anything. I had only searched for it but didn´t receive any good answers.