Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java class edu.kennesaw.seclass.FlawedClass in directory /src. (The actual path will obviously reflect the package structure. is the directory where you are in.) Task

Create a Java class edu.kennesaw.seclass.FlawedClass in directory

/src. (The actual path will obviously reflect the package structure. is the directory where you are in.)

Task 1: Add to the class a method called flawedMethod1 that contains a division by zero fault such that (1) it is possible to create a test suite that achieves 100% branch coverage and does not reveal the fault, and (2) it is possible to create a test suite that achieves 100% statement coverage and reveals the fault.

The method can have any signature.

If you think it is not possible to create a method meeting both requirements, then:

create an empty method.

add a comment in the (empty) body of the method that concisely but convincingly explains why creating such method is not possible.

FlawedClassTestBC1 should achieve 100% branch coverage of flawedMethod1 and not reveal the fault therein.

FlawedClassTestSC1 should achieve 100% statement coverage of flawedMethod1 and reveal the fault therein.

Both classes should be saved in directory

/test.

(Optional) Conversely, if you were able to create the method, then create two JUnit test classes edu.kennesaw.seclass.FlawedClassTestBC1 and edu.kennesaw.seclass.FlawedClassTestSC1 for class FlawedClass as follows:

Task 2: Add to the class a method called flawedMethod2 that contains a division by zero fault such that (1) it is possible to create a test suite that achieves less than 100% statement coverage and reveals the fault, and (2) every test suite that achieves 100% statement coverage does not reveal the fault.

The method can have any signature.

If you think it is not possible to create a method meeting both requirements, then:

create an empty method.

add a comment in the (empty) body of the method that concisely but convincingly explains why creating such method is not possible.

(Optional) Conversely, if you were able to create the method, then create two JUnit test classes edu.kennesaw.seclass.FlawedClassTestSC2a and edu.kennesaw.seclass.FlawedClassTestSC2b for class FlawedClass as follows:

FlawedClassTestSC2a should achieve less than 100% statement coverage of flawedMethod2 and reveal the fault therein.

FlawedClassTestSC2b should achieve 100% statement coverage of flawedMethod2 and not reveal the fault therein.

Both classes should be saved in directory

/test.

Task 3: Add to the class a method called flawedMethod3 that contains a division by zero fault such that (1) it is possible to create a test suite that achieves 100% branch coverage and does not reveal the fault, and (2) every test suite that achieves 100% statement coverage reveals the fault.

create an empty method.

add a comment in the (empty) body of the method that concisely but convincingly explains why creating such method is not possible.

FlawedClassTestBC3 should achieve 100% branch coverage of flawedMethod3 and not reveal the fault therein.

FlawedClassTestSC3 should achieve 100% statement coverage of flawedMethod3 and reveal the fault therein.

Both classes should be saved in directory

/test.

The method can have any signature.

If you think it is not possible to create a method meeting both requirements, then:

(Optional)Conversely, if you were able to create the method, then create two JUnit test classes edu.kennesaw.FlawedClassTestBC3 and edu.kennesaw.seclass.FlawedClassTestSC3 for class FlawedClass as follows:

Task 4: Add to class FlawedClass the method flawedMethod4 provided here, including the final, commented part (i.e., the table):

public boolean flawedMethod4 (boolean a, boolean b) { int x = 2; int y = 6; if(a) x = 4; else y = y / x; if(b) x -= 1; else x += 1; return ((2/(y-x)) >= 1); }

// | a | b |output| // ================ // | T | T | | // | T | F | | // | F | T | | // | F | F | | // ================ // Coverage required: __________

Fill in the table in the comments, as follows:

FlawedClassTestXC4 should achieve 100% of the coverage named in your comment for flawedMethod4 and reveal the fault therein.

For every possible input, write whether the output is T (true), F (false), or E (division by 0 exception)

In the Coverage required entry, write the minimal level of coverage that a test suite must achieve to guarantee that the fault in the code is revealed (i.e., to guarantee that a division by zero occurs), among statement, branch, and path coverage. In other words: If every test suite achieving statement coverage reveals the fault, then you should write Coverage required: statement coverage. If statement coverage does not guarantee that the fault is revealed, but branch coverage does, you should write Coverage required: branch coverage. If neither statement nor branch coverage guarantees that the fault is revealed, but path coverage does, you should write Coverage required: path coverage Finally, if none of these coverage criteria considered guarantees that the fault is revealed, you should write Coverage required: N/A

(Optional)If the answer is not N/A, create a JUnit test class edu.kennesaw.seclass.FlawedClassTestXC4 for class FlawedClass as follows:

Notes (importantmake sure to read carefully):

By reveal the fault therein, we mean that the tests which show the division by zero fault should fail with an uncaught exception, so that they are easy to spot.

Do not use compound predicates in your code for the methods of class FlawedClass. That is, only use simple predicates in the form ( ), such as if (x > 5) or while (x >= t). In other words, you cannot use logical operators (such as &&, ||) in your predicates.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions