100% found this document useful (1 vote)
851 views

Demo Test Java

Unit Testing the Demo (isTriangle) Program. In this assignment, you'll get some practice at building effective unit tests. Using the example from our videos, you'll be developing tests for the Demo class, including the isTriangle() and main() methods. Your task is to create a file, DemoTest.java, which properly tests the Demo class to ensure it is working properly. The correct Demo.java file is provided for your use.

Uploaded by

Roldan DG
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
851 views

Demo Test Java

Unit Testing the Demo (isTriangle) Program. In this assignment, you'll get some practice at building effective unit tests. Using the example from our videos, you'll be developing tests for the Demo class, including the isTriangle() and main() methods. Your task is to create a file, DemoTest.java, which properly tests the Demo class to ensure it is working properly. The correct Demo.java file is provided for your use.

Uploaded by

Roldan DG
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to Software Testing

Université du Minnesota

Unit Testing the Demo (isTriangle) Program

Building Unit Tests with JUnit


==============================
In this assignment, you'll get some practice at building effective unit
tests. Using the example from our videos, you'll be developing tests for
the Demo class, including the isTriangle() and main() methods.

Your task is to create a file, DemoTest.java, which properly tests the Demo
class to ensure it is working properly. The correct Demo.java file is
provided for your use.

Below, are instructions to get you started. We provide instructions for


building and running the tests. We've provided you with the files needed
to get you started. Information about the directory structure is also
included below.

### Deliverable
Your deliverable is the `DemoTest.java` which tests the Demo class.

import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import static org.junit.Assert.*;

/**
* The class containing your tests for the {@link
Demo} class. Make sure you
* test all methods in this class (including both
* {@link Demo#main(String[])} and
* {@link Demo#isTriangle(double, double, double)}).
*/
public class DemoTest {
@Test
public void test_is_triangle_1() {
assertTrue(Demo.isTriangle(3,4,5));
}
@Test
public void test_is_triangle_2() {
assertTrue(Demo.isTriangle(5,12,13));
}
@Test
public void test_is_triangle_3() {
assertTrue(Demo.isTriangle(5, 13, 12));
}
@Test
public void test_is_triangle_4() {
assertTrue(Demo.isTriangle(12, 5, 13));
}
@Test
public void test_is_triangle_5() {
assertTrue(Demo.isTriangle(12, 13, 5));
}
@Test
public void test_is_NOT_triangle_1() {
assertFalse(Demo.isTriangle(5,7, 13));
}

@Test
public void test_is_NOT_triangle_2() {
assertFalse(Demo.isTriangle(5,13,7));
}
@Test
public void test_is_NoT_triangle_3() {
assertFalse(Demo.isTriangle(1,2,-1));
}
@Test
public void test_main_program_1() {
ByteArrayInputStream in =
new ByteArrayInputStream("5\n12\n13\
n".getBytes());
System.setIn(in);
ByteArrayOutputStream out = new
ByteArrayOutputStream();
System.setOut(new PrintStream(out));

String[] args = {};


Demo.main(args);
String consoleOutput = "Enter side 1: " +
System.lineSeparator();
consoleOutput += "Enter side 2: " +
System.lineSeparator();
consoleOutput += "Enter side 3: " +
System.lineSeparator();
consoleOutput += "This is a triangle." +
System.lineSeparator();

assertEquals(consoleOutput, out.toString());

You might also like