Lab02 Testing 08 02 - tut work PDF

Title Lab02 Testing 08 02 - tut work
Course Intermediate Object-Oriented Programming
Institution La Trobe University
Pages 6
File Size 241.4 KB
File Type PDF
Total Downloads 8
Total Views 47

Summary

Intermediate Object-Oriented Programming Laboratory 02 (Week 03) Handout Introduction This lab aims to continue your learning of software engineering principles and expand your knowledge of various testing methodologies. Objectives    To understand the concepts of black box testing To understand ...


Description

Intermediate Object-Oriented Programming

Laboratory 02 (Week 03) Handout

Introduction This lab aims to continue your learning of software engineering principles and expand your knowledge of various testing methodologies.

Objectives   

To understand the concepts of black box testing To understand the concepts of white box testing To apply both black box and white box testing methodologies

1

Question 1 Consider writing a method that takes three integer arguments representing the three sides of a triangle – the method returns a string

– – – –

“equilateral” if all the side lengths are equal “isosceles” if exactly 2 side lengths are equal “scalene” if no sides are equal “invalid” if the three integers could not be the sides of a triangle

What test cases would you choose?

Input 1

Input 2

Input 3

Expected output

2

Reason for test

Question 2 Complete the class method that codes the triangle problem described in Question 1. You must put it in a class called Geometry and give it the method header as shown below. public class Geometry { public static String triangleType(int a, int b, int c) { ... } }

Question 3 Expand the TriangleTypeTester.java program on the next page, to test the method you wrote in Question 2 containing your tests from the table in Question 1.

3

public class TriangleTypeTester { private static int testNr = 0; private static int passedTests = 0; private static int failedTests = 0; public static void main(String[] args) { System.out.println("Tests"); System.out.println("-----"); // First test (for example) String testDescription = "Inputs form 3 sides of a scalene triangle"; test(3, 4, 5, testDescription, "scalene"); // Next tests

// Testing Report int totalTests = failedTests + passedTests; System.out.println(); System.out.println("Testing Report"); System.out.println("--------------"); System.out.println("PASSED tests: " + passedTests); System.out.println("FAILED tests: " + failedTests); System.out.println("TOTAL tests: " + totalTests); } public static void test(int a, int b, int c, String testDescription, String expected) { System.out.println("\nTest " + (++ testNr) + ": " + testDescription); String result = Geometry.triangleType(a, b, c); System.out.println("Expected Result: " + expected); System.out.println("Actual Result: " + result); if (result.equals(expected)) // the expected result { System.out.println("SUCCESSFUL"); ++passedTests; } else { System.out.println("FAILED"); ++failedTests; } } }

4

Question 4 (Optional) Swap your Geometry program with another student (see below) and run your tests on the other student’s class. Note any tests that fail and report those to the other student. If your Geometry class has flaws reported to you, see if you can fix them and rerun the tests that reported a fault.

How to transfer files between Unix accounts You can use scp command to copy a file from one account to another. The general syntax is scp source destination

where either source or destination can be in another account (or even on another host). The command will prompt for the password of the other account. But you have to be very careful because this scp command will overwrite any file with the same name as source file in the destination. Therefore, you need to ensure that you do not accidentally overwrite your Geometry class or that of the other student (e.g. by saving a copy of the Geometry class and/or creating a new directory to test the other student’s class). You can use the scp command below to copy your Geometry class to the other student’s account: scp Geometry.java username@latcs8:IOO/Lab02/otherStudent/Geometry.java

5

Question 5 (Optional) Looking at your own code again, add white-box tests to your initial tests. Use the strategies given in Practice Class 2, that is: 1. Choose tests that will execute each branch of a selection statement at least once 2. For compound Boolean conditions o containing and (&&) choose tests where 

all the subconditions are true



all, but one, are true (if possible)

o containing or (||) choose tests where 

all the subconditions are false



all, but one, are false (if possible)

3. Choose tests that will result in the execution of a looping statement no times, once, multiple, and the maximum number of times (if each is possible)

If your triangleType method had flaws that were discovered, see if you can fix them and rerun the tests that reported a fault. 

6...


Similar Free PDFs