Β
Goals:
βΒ Β Β Β Get familiar with white-box testing.
βΒ Β Β Β Understand some subtleties of structural coverage.
Β
Preliminary Steps:
βΒ Β Β Β Download the archive assignment 6.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/FaultyClass.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.1.jar Β
NOTE: Β If extracting using Windows βExtract Allβ¦β, the Assignment6 directory may be nested in an additional directory. Drag it to the root directory.
Β
Instructions:
To complete the assignment, perform the following tasks (after reading the Instructions and Notes in their entirety). If your submission does not pass the Gradescope checks, it will not be graded and will receive a 0.
Β
Β
βΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β faultyMethod1
and at least two branches such thatΒ (1) it is possible to create a test suite that achieves 100% path coverage and reveals the fault, and (2) every possible test suite that achieves 100% branch coverage does not reveal the fault.
βΒ Β Β Β The method signature:
βͺΒ Should remain public static void faultyMethod1 βͺ May accept any parameter(s) β you choose the types and names βΒ Β 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:
βͺΒ FaultyClassTestPC1 should achieve 100% path coverage of faultyMethod1 and reveal the fault therein.
βͺΒ FaultyClassTestBC1 should achieve 100% branch coverage of faultyMethod1 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.)
Β
Β
Β
βΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β faultyMethod2
and at least two branches, 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 possible test suite that reveals the fault achieves 100% statement coverage.
βΒ Β Β Β The method signature:
βͺΒ Should remain public static void faultyMethod2 βͺ May accept any parameter(s) β you choose the types and names βΒ Β 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:
βͺΒ FaultyClassTestBC2 should achieve 100% branch coverage of faultyMethod2 and not reveal the fault therein.
βͺΒ FaultyClassTestSC2 should achieve 100% statement coverage of faultyMethod2 and reveal the fault therein.
βͺΒ Both classes should be saved in the directory <dir>/test.
Β
Β
Β
Β Β Β Β Β Β Β Β Β β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β faultyMethod3
and at least two branches, such thatΒ (1) it is possible to create a test suite that achieves 100% statement coverage and does not reveal the fault, and (2) every possible test suite that achieves 100% branch coverage reveals the fault.
β The method signature:
βͺ Should remain public static void faultyMethod3 βͺ May accept any parameter(s) β you choose the types and names βΒ Β 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:
βͺΒ FaultyClassTestSC3 should achieve 100% statement coverage of faultyMethod3 and not reveal the fault therein.
βͺΒ FaultyClassTestBC3 should achieve 100% branch coverage of faultyMethod3 and reveal the fault therein.
βͺΒ Both classes should be saved in the directory <dir>/test.
Β
Β
Β
Β
Β
β : Class FaultyClass contains the following method faultyMethod4: public static int faultyMethod4(int a, int b, int c, int d, boolean e) {
Β Β Β int result = 0; Β Β Β Β if (a > b) { Β Β Β Β Β Β Β Β result = 1; Β Β Β Β } else {
Β Β Β Β Β Β Β if (((c != 0) || (d == 0)) && (e)) { Β Β Β Β Β Β Β Β Β Β Β Β result = 2; Β Β Β Β Β Β Β Β } else { Β Β Β Β Β Β Β Β Β Β Β Β result = 3;
Β Β Β Β Β Β Β } Β Β Β Β }
Β Β Β return result;
} Β
Create two JUnit test classes as follows, where each test case performs a single invocation of faultyMethod4. o FaultyClassTestSC4 should achieve 100% statement coverage of faultyMethod4 and contain at most 3 test cases. o FaultyClassTestMCDC4 should achieve 100% Modified
Condition/Decision Coverage (MC/DC) of faultyMethod4 and contain at most 8 test cases.
oΒ Β Partial credit will NOT be awarded if FaultyClassTestSC4 and
FaultyClassTestMCDC4 do not satisfy their respective requirements.Β o Bonus Points: If FaultyClassTestMCDC4 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).
oΒ Β Both classes should be saved in the directory <dir>/test.
Β
Β
Β
Β
β Task 5: Method faultyMethod5 in the provided class FaultyClass contains:
β The code below, commented out:
Β
Β Β Β Β Β Β Β Β Β /*-
public static boolean faultyMethod5(boolean a, boolean b) { Β Β Β Β Β int x = 2;Β Β Β Β Β Β int y = -4;Β Β
Β Β Β Β Β Β if(a)Β Β Β Β Β Β Β Β Β Β x -= 2;Β Β Β Β Β Β Β elseΒ Β Β Β Β Β Β Β Β Β y += 1;Β Β Β Β Β Β if(b)Β Β Β Β Β Β Β Β Β Β x -= 1; Β Β Β Β Β elseΒ Β Β Β Β Β Β Β Β Β Β y += 3; Β
Β Β Β return (y/x < 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 faultyMethod[1] method.
Β
Β
Notes (importantβmake sure to read carefully):
1.Β Β Β Β Β When we say βcreate in class FaultyClass a method called faultyMethod Nβ, we mean that you should complete the placeholder for that method provided in the skeleton class, by either modifying its code (and possibly method parameter(s)) or providing a suitable comment and an empty body.
2.Β Β Β Β Β Explanations of why a method cannot be created, if any, must be written using the format provided in the method examples in the FaultyClass skeleton class.
3.Β Β Β Β Β Committing (or omitting) class ExampleTestSC1 has no effect on your grade.
4.Β Β Β Β Β Similarly, leaving or removing the example methods provided in the FaultyClass skeleton has no effect on your grade.
Β
6.Β Β Β Β Β Β Β Β Β For tasks 1 through 3, if the task is possible, every one of these methods can be written with simple, short code. For these 3 tasks, you cannot use any of the following constructs in your solution:[2]
a.Β Β Β Compound Predicates.Β That is, only use simple predicates in the form
(<operand1> <operator> <operand2>), such as βif (x > 5)β or βif (a >
b)β. In other words, you cannot use logical operators (such as &&, ||) in your predicates.
b.Β Β Nested if statements and βelse ifβ constructions.
c.Β Β Β throw new ArithmeticException. The code should naturally fail due to an arithmetic operation that results in a divide-by-zero exception.
d.Β Β Loops.Β (while, for, do, etc.)
e.Β Β Method calls.Β Your method should be self-contained and not call any other methods (including itself).
f.Β Β Β Conditional (trinary) operators.Β (No use of the β<condition> ? <case if true> : <case if false>β construct.)
g.Β Β Β Switch statements.
h.Β Β Streams, lambdas, or other newer complex features of the language.
i.Β Β Β Β Dead or unreachable code.
j.Β Β Β Static variables or class variables.
7.Β Β Β Β Β Β Β Β Β A single if/else statement already creates 2 branches. You do not need multiple if statements to satisfy the βat least 2 branchesβ requirement.
8.Β Β Β Β Β Β Β Β Β You should not modify the methods provided in tasks 4 and 5.
9.Β Β Β Β Β Β Β Β Β Read the requirements carefully. For example, βEvery possible test suiteβ¦β means all conceivable test suites for your method, not only the example test suite you write.Β
10.Β Β Β Β Β Β Β Your code should compile and run out of the box with Java 17.
11.Β Β Β Β Β Β Β Use the provided JUnit library for your JUnit tests.
12.Β Β Β Β Β Β Β Unlike normal tests, an assertion is unnecessary. However, if you choose to include one, ensure that it does not interfere with the expected coverage results.
13.Β Β Β Β Β Β Β We strongly recommend computing coverage manually, as tools sometimes use slightly different definitions of coverage and may have some quirks. Given that the solutions typically consist of very simple methods, it should be easy to compute coverage by hand (which is how we do it when we grade the assignment). Although the lectures imply that braces count as statements with regard to coverage, you may ignore braces while determining your coverage.
Β
Β
Β
14.Β Β Β Β Β Β Β This is an individual assignment. You are not supposed to collaborate with your team members (or any other person) to solve it. We will enforce this by running a plagiarism detection tool on all assignments. Given the numerous different ways in which the assignment can be solved, similar solutions will be (1) easily spotted and (2) hard to justify.
15.Β Β Β Β Β Β Β Similarly, make sure not to post on Ed Discussion any solution, whether complete or partial, and also to avoid questions that are too specific and may reveal information about a specific solution, or imply which tasks you believe are possible. You can obviously ask these types of questions privately to the instructors.
Β
Submission:
βΒ Β Β Β As usual, commit and push your code to your individual, assigned private repository.
βΒ Β Β Β Make sure that all Java files are committed and pushed (i.e., class FaultyClass and any created JUnit test classes). Also make sure to commit and push the provided libraries (lib directory), which are typically excluded by the β.gitignoreβ file. To do so, you may need to force add the jar files (i.e., βgit add -f lib/*β).
βΒ Β Β Β You can check that you committed and pushed all the files you needed by doing the following:
β Clone a fresh copy of your personal repo in another directory β Go to directory Assignment6 in this fresh clone of your repo
β Compile your code. One way to do is to run, from a Unix-like shell:
javac -cp lib/\* -d classes src/edu/gatech/seclass/FaultyClass.java test/edu/gatech/seclass/*.java
β Run one or more of your tests. Again, from a Unix-like shell, you can run:
java -cp classes:lib/\* org.junit.platform.console.ConsoleLauncher -select-class edu.gatech.seclass.<test class name>[3]
(at least one of the tests should fail with an ArithmeticException)
βΒ Β Β Β Submit on Gradescope a file called submission.txt that contains, in two separate lines, (1) your GT username and (2) the commit ID for your submission. For example, the content of file submission.txt for George P. Burdell could look something like the following:
submission.txt
gpburdell1
81b2f59
As soon as you submit, Gradescope will check your assignment by making sure that your files are present and in the correct location, compiling the code,
Β
running your tests, and performing some sanity checks on the outcome of such tests. If you pass all these checks, you will see a placeholder grade of 10 and a positive message from Gradescope. Otherwise, you will see a grade of 0 and an error message with some diagnostic information. Please note that a positive response from Gradescope only indicates that you passed the sanity checks and is meant to prevent a number of trivial errors. Please also note that if your submission does not pass the Gradescope checks, it will not be graded and will receive a 0, so please make sure to pay attention to the feedback you receive when you submit.[4]
Β
Β
[1] . Β Β By βreveal the fault thereinβ, we mean that the tests that trigger the division by zero fault should FAIL with an uncaught ArithmeticException fault, so that they are easy to spot. Make sure that the correct tests fail,
and show the correct type of exception when they fail. See ExampleTestSC1 for an example.
Β
[2] Using any of these constructs would result in a zero for that task.
[3] If using a Windows-based system, you may need to run java -cp βclasses;lib/*β org.junit.platform.console.ConsoleLauncher βselect-class edu.gatech.seclass.<test class name> instead.
[4] Although we tested the checker, it is possible that it might not handle correctly some corner cases. If you receive feedback that seems to be incorrect, please contact us on Ed Discussion.







