这是一篇关于White-Box测试的作业代写

 

Goals:

  • Get familiar with white-box testing.
  • Understand some subtleties of structural coverage.

Preliminary Steps:

  • Download the archive assignment6.tar.gz.
  • Extract the archive in the root directory of the personal repo we assigned to you.

○ This will create a directory called Assignment6 in the root directory of the repo. Hereafter, we will call this directory <dir>.

○ This will also create the following files:

■ A skeleton of the class that you need to complete for this assignment:

<dir>/src/edu/gatech/seclass/WeakClass.java

■ An example of the kind of JUnit test classes you need to create for this assignment:

<dir>/test/edu/gatech/seclass/ExampleTestSC1.java

■ A JUnit library to be used for the assignment:

<dir>/lib/junit-platform-console-standalone-1.9.0.jar

Instructions:

To complete the assignment, perform the following tasks (after reading the instructions in their entirety):

  • Task 1: Create in class WeakClass a method called weakMethod1 that contains a division by zero fault and at least two branches, such that (1) it is possible to create a non-empty test suite that achieves less than 100% statement coverage and reveals the fault, and (2) it is possible to create a non-empty test suite that achieves 100% statement coverage and does not reveal the fault.

○ The method can have any signature.

See note 6 below for prohibited language constructs.

○ 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 a method is not possible.○ Conversely, if you were able to create the method, create two JUnit test classes as follows:

■ WeakClassTestSC1a should achieve less than 100% statement coverage of weakMethod1 and reveal the fault therein.

■ WeakClassTestSC1b should achieve 100% statement coverage of weakMethod1 and not reveal the fault therein.

■ Both classes should be saved in the directory <dir>/test. (The full actual path should obviously also reflect the package structure, and the same holds for the test classes in the subsequent tasks.)

  • Task 2: Create in class WeakClass a method called weakMethod2 that contains a division by zero fault and at least two branches, such that (1) every possible test suite that achieves 100% statement coverage but less  than 100% branch coverage does not reveal the fault, and (2) it is possible to create a non-empty test suite that achieves 100% branch coverage and reveals the fault.

○ The method can have any signature.

See note 6 below for prohibited language constructs.

○ 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 a method is not possible.

○ Conversely, if you were able to create the method, create two JUnit test classes as follows:

■ WeakClassTestSC2 should achieve 100% statement coverage and less than 100% branch coverage of weakMethod2 and not reveal the fault therein.

■ WeakClassTestBC2 should achieve 100% branch coverage of weakMethod2 and reveal the fault therein.

■ Both classes should be saved in the directory <dir>/test.

  • Task 3: Create in class WeakClass a method called weakMethod3 that contains a division by zero fault and at least two branches, such that (1) every possible test suite that achieves 100% statement coverage reveals the fault, and (2) it is possible to create a non-empty test suite that achieves 100% path coverage and does not reveal the fault.

○ The method can have any signature.

See note 6 below for prohibited language constructs.

○ 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 conciselybut convincingly explains why creating such a method is not possible.

○ Conversely, if you were able to create the method, create two JUnit test classes as follows:

■ WeakClassTestSC3 should achieve 100% statement coverage of weakMethod3 and reveal the fault therein.

■ WeakClassTestPC3 should achieve 100% path coverage of weakMethod3 and does not reveal the fault therein.

■ Both classes should be saved in the directory <dir>/test.

  • Task 4: Class WeakClass contains the following method weakMethod4:

public static int weakMethod4(boolean a, boolean b, int c, int d, int e) {

int result = 0;

if (a != b) {

if ((c < 0) && (d == 0) || (e > 0)) {

result = 1;

} else {

result = 2;

}

} else {

result = 3;

}

return result;

}

Create two JUnit test classes as follows, where each test case performs a

single invocation of weakMethod4.

■ WeakClassTestSC4 should achieve 100% statement coverage of weakMethod4 and contain at most 3 test cases.

■ WeakClassTestMCDC4 should achieve 100% Modified Condition/Decision Coverage (MC/DC) of weakMethod4 and contain at most 8 test cases.

■ Partial credit will NOT be awarded if WeakClassTestSC4 and WeakClassTestMCDC4 do not satisfy their respective requirements.

Bonus Points: If WeakClassTestMCDC4 achieves 100% MC/DC coverage with the minimum possible number of test cases, then you will receive 10 bonus points. Determining the actual minimum is part of the bonus task (but you may safely assume the minimum is less than or equal to 8).

■ Both classes should be saved in the directory <dir>/test.● Task 5: Method weakMethod5 in the provided class WeakClass contains:

○ The code below, commented out:

public static boolean weakMethod5(boolean a, boolean b) {

int x;

int y;

if (a) {

x = 0;

}

else {

x = -2;

}

if (b) {

y = 2*x – x;

}

else {

y = 1;

}

return ((x+1)/y > 0);

}

○ The following table, where you can provide your responses as strings (please note that the table in the code has a slightly different format because we want to be able to run that part of the code):

// ================

//

// Replace the “?” in column “output” with “T”, “F”, or “E”:

//

// | a | b |output|

// ================

// | T | T | ? |

// | T | F | ? |

// | F | T | ? |

// | F | F | ? |

// ================

○ The following sentences, where you can again provide your responses as strings (also in this case, the format in the code is different to make the code executable):

//

// Replace the “?” in the following sentences with “NEVER”,

// “SOMETIMES” or “ALWAYS”:

//

// – Test suites with 100% statement coverage “?”

// reveal the fault in this method.

// – Test suites with 100% branch coverage “?”

// reveal the fault in this method.

// – Test suites with 100% path coverage “?”

// reveal the fault in this method.// ================

Fill in your answers in the method, as follows:

○ For every possible input, replace the “?” in column “output” of the table, with “T” to indicate that the return value is true, or “F” to indicate that the return value is false, or “E” to indicate that the method exits with a division by zero error.

○ In the sentences following the table, replace the “?” with “NEVER”,“SOMETIMES”, or “ALWAYS” to indicate whether a test suite with 100% coverage for the specified criterion NEVER reveals the fault, SOMETIMES reveals the fault, or ALWAYS reveals the fault in the weakMethod5 method.


EasyDue™ 支持PayPal, AliPay, WechatPay, Taobao等各种付款方式!

E-mail: easydue@outlook.com  微信:easydue


EasyDue™是一个服务全球中国留学生的专业代写公司
专注提供稳定可靠的北美、澳洲、英国代写服务
专注提供CS、统计、金融、经济、数学等覆盖100+专业的作业代写服务