0% found this document useful (0 votes)
23 views2 pages

Code Coverage Analysis for Ward App

The document outlines a lab assignment for a BSc (Hons) in Information Technology focusing on code coverage analysis for a Ward application in Java. It details the requirements for managing patient admissions and discharges, along with specific conditions for surplus patients. The assignment includes tasks for compiling and running the Java program, executing test cases, calculating coverage metrics, and updating test cases to achieve full coverage.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Code Coverage Analysis for Ward App

The document outlines a lab assignment for a BSc (Hons) in Information Technology focusing on code coverage analysis for a Ward application in Java. It details the requirements for managing patient admissions and discharges, along with specific conditions for surplus patients. The assignment includes tasks for compiling and running the Java program, executing test cases, calculating coverage metrics, and updating test cases to achieve full coverage.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BSc (Hons) in Information Technology

Year 4
Lab – Code Coverage Analysis

IT4100 – SQA Semester 1

Code coverage analysis: Code Coverage Analysis is the process of discovering code within a program
that is not being exercised by test cases. This information can then be used to improve the test suite, either
by adding tests or modifying existing tests to increase coverage.

Following are the requirements of the Ward application in [Link] file.


• The user has to add the admitted and discharged patients to a ward.
• The system has to calculate the surplus of patients by getting the admitted patient count reduced from
the discharged patients count.
• If there is a positive surplus of patients, then the system has to check the following conditions regarding
the surplus value and display the relevant output.
1. If the surplus is greater than or equal to 50, the system has to alert that the medical facilities are
insufficient.
2. If the surplus is less than 50 and greater or equal to 25, the system has to indicate that 5 patients
can be added to this ward, 10 patients can be added to the next ward and the remaining has to be
moved to another hospital.
3. If the surplus is less than 25 and greater or equal to 10, the system has to indicate that 5 patients can
be added to the next ward and the remaining can be added to this ward with more medical facilities.
4. If the surplus is less than 10 and greater or equal to 5, the system has to indicate that patients can
be added to this ward with more medical facilities.
5. If the surplus is less than 5, the system has to indicate the that patients can be added to this ward.
• If there is a negative surplus of patients, then the system has to check the following conditions regarding
the surplus value and display the relevant output.
1. If the surplus is less than 0, the system has to display that all patients can be added to the ward
without any issues.
2. If the surplus is even less than -10, the system has to display that the ward is not in a critical stage.

1
BSc (Hons) in Information Technology
Year 4
Lab – Code Coverage Analysis

IT4100 – SQA Semester 1

Task 1
Compile and Run [Link] file in the command prompt.
• Use javac command to compile a java program.
• Use java command to run a java file.

Task 2
Execute the given test cases and complete the fields in Table 1.

Table 1: Test cases to test the Ward Application.


#Test Test Inputs Expected Actual Test Result
Case Admitted Discharged Result Result (Pass/Fail)
1 20 5
2 62 10
3 2 5
4 50 20
5 40 38

Task 3
Calculate the statement coverage, decision coverage and the path coverage of testing the [Link] file
using the testcases given in Table 1.

Task 4
Identify suitable test case(s) to achieve 100% statement coverage, decision coverage and path coverage.

Task 5
Update Table 1 by adding the new test cases identified for the previous task. Execute the new test cases
and complete Table 1.

Task 6
Fix the error in [Link]. Rerun the test cases to ensure that all test cases are passed.

Common questions

Powered by AI

Achieving 100% path coverage ensures that every potential path through the code is tested, which helps identify errors that might occur in complex conditional logic not covered by less exhaustive testing criteria. It increases the likelihood of discovering hidden defects and improves the robustness and reliability of the software, particularly in applications like Ward.java, which involve numerous conditional checks .

The Ward application can be compiled using the `javac` command and run using the `java` command from the command line. Specifically, one would first compile the Ward.java file using `javac Ward.java` and then execute it using `java Ward` .

The Ward application categorizes patient surplus based on severity levels with specific system responses: if surplus is >= 50, it alerts that medical facilities are insufficient; if surplus is < 50 and >= 25, it suggests adding patients to the ward, another ward, and another hospital; if surplus is < 25 and >= 10, it advises adding patients to another ward and this ward with more facilities; if surplus is < 10 and >= 5, it indicates that patients can be added with more facilities; and if surplus is < 5, it shows that patients can be added to the ward .

To ensure complete decision coverage for the Ward application, new test cases must be designed to explore each decision point within the code. This means testing each conditional branch for true and false outcomes, ensuring all logical paths are evaluated. For the Ward application, this includes creating tests for every possible case of patient surpluses and deficits, and their associated condition-based outputs .

Updating and executing new test cases in the context of the Ward application is essential to ensure all possible scenarios are tested and the system behaves as expected under varied conditions. This approach helps in achieving higher code coverage metrics and reveals potential defects early, enhancing the reliability and robustness of the application .

Fixing errors in the Ward.java file involves debugging to identify and correct issues in the code, followed by rerunning the test cases to verify the fixes. All test cases should pass without failures to ensure the integrity of the fixes. This process may involve adjusting logic, correcting syntax errors, and retesting with both existing and new test cases to confirm comprehensive coverage .

In the Ward application, a negative surplus indicates ward status as follows: a surplus less than 0 allows all patients to be added to the ward without issues, while if the surplus is even less than -10, it denotes that the ward is not in a critical stage .

Code coverage analysis is the process of discovering which parts of a program's code are not being exercised by test cases. This analysis helps in identifying portions of code that lack testing, allowing for improvement of the test suite by adding or modifying tests to increase coverage. It ensures that more of the program's code is tested, potentially leading to the identification of hidden errors and improving software quality .

To achieve 100% statement coverage in testing the Ward.java file, you need to construct test cases that execute every line of code in the application at least once. This involves creating test scenarios that cover all conditions, branches, and outcomes described in the application requirements, including all variations of patient surplus, both positive and negative. Such thorough testing ensures that all executable statements are exercised .

Calculating statement coverage involves determining the percentage of executable code lines exercised by test cases. Decision coverage measures whether each decision point has been evaluated for both true and false outcomes. Path coverage refers to testing all possible paths through the application, including those through loops and conditional logic. For Ward.java, this involves executing tests that cover every logic branch, condition, and decision point, ensuring that the application’s complex patient management scenarios are thoroughly evaluated .

You might also like