Assignment#03
Assignment#03
Part 1:
import java.util.*;
import org.junit.Test;
import org.junit.Assert;
@Test
public void testHeapsort2() {
System.out.println("test-case-2: heapsort using JUnit 4");
int[] input = {8, 5, 3, 1, 9, 6, 0, 7, 4, 2, 5};
HeapSort instance = new HeapSort();
instance.main(new String[] {"arg1", "arg2", "arg3"});
Assert.assertNotSame(new int[]{1,0,2,3,4,5,5,6,7,8,9}, instance.heapsort(input));
}
@Test
public void testHeapsort3() {
System.out.println("test-case-4: heapsort using JUnit 4");
int[] input = {8, 5, 3, 1, 9};
HeapSort instance = new HeapSort();
Assert.assertArrayEquals(new int[]{1,3,5,8,9}, instance.heapsort(input));
}
@Test
public void testHeapsort4() { //Test case for empty input array
System.out.println("test-case-6: heapsort using JUnit 4");
int[] input = {};
HeapSort instance = new HeapSort();
Assert.assertArrayEquals(new int[]{}, instance.heapsort(input));
}
}
All Test Cases run together: Coverage achieved (Branch/Decision Coverage): 100%
Individual Test Case:
Test Case#01:
Coverage achieved (Branch/Decision Coverage): 100%
Test Case#02:
Coverage achieved (Branch/Decision Coverage): 100%
Test Case#03:
Coverage achieved (Branch/Decision Coverage): 100%
Test Case#04:
Coverage achieved (Branch/Decision Coverage): 94.4%
5. Evaluation of the tool’s usefulness:
EclEmma is extremely easy to use, which makes it outstanding. It can generate the output
report of the code coverage in a variety of formats, such as HTML, XML, etc. It is free to use. It
has several counters like branch counters, line counters, etc. which makes it a very good
analytical tool in terms of code coverage. This tool has no external dependencies and is pure
100% java and works in almost every version of JVM (1.2.x or higher). It also helps in merging
the test runs and the coverage data.
Report items will be highlighted with coverage levels below user-specified thresholds. The
consequence of a source highlighting is additionally straightforwardly apparent in the Java
source editors. An adaptable shading color code features completely, mostly, and not covered
lines. This works for your own source code just as for source appended to instrumented
outside libraries.
Thus, EclEmma is extremely useful in terms of the Java Code Coverage tool.
PART-2:
FindBugs uses special bytecode scanning strategies to analyze static Java code. It
uses the concept of bug patterns. It is free to use.
Types of Analysis: All bugs/warnings are classified in four positions: (i) scariest, (ii) scary, (iii)
troubling, and (iv) of concern. This can be an indication to the developer of the conceivable
impact/severity of the warnings. The current adaptation of FindBugs reports around 400
warnings within the nine categories:
Multithreaded Correctness 45
Class's writeObject() method is synchronized but nothing
else is
Method concatenates strings using + in a loop
Performance 27
Method invokes inefficient Boolean constructor
HeapSort.java
import java.util.*;
public class HeapSort{
import org.junit.Test;
import org.junit.Assert;
@Test
public void testHeapsort2() {
System.out.println("test-case-2: heapsort using JUnit 4");
int[] input = {8, 5, 3, 1, 9, 6, 0, 7, 4, 2, 5};
HeapSort instance = new HeapSort();
instance.main(new String[] {"arg1", "arg2", "arg3"});
Assert.assertNotSame(new int[]{1,0,2,3,4,5,5,6,7,8,9}, instance.heapsort(input));
}
@Test
public void testHeapsort3() {
System.out.println("test-case-4: heapsort using JUnit 4");
int[] input = {8, 5, 3, 1, 9};
HeapSort instance = new HeapSort();
instance.main(new String[] {"arg1", "arg2", "arg3"});
Assert.assertArrayEquals(new int[]{1,3,5,8,9}, instance.heapsort(input));
}
@Test
public void testHeapsort4() { //Test case for empty input array
System.out.println("test-case-6: heapsort using JUnit 4");
int[] input = {};
HeapSort instance = new HeapSort();
instance.main(new String[] {"arg1", "arg2", "arg3"});
Assert.assertArrayEquals(new int[]{}, instance.heapsort(input));
}
}
3. Screenshots of FindBugs:
FindBugs works similar to the Java compiler: as quickly as you hit CTRL+S, Eclipse will
collect the code and begin bug analysis incrementally. FindBugs can find an
outstanding quantity of exclusive bug patterns, which are occasionally difficult to
reproduce or debug. FindBugs has a very small wide variety of false positives. Even if
you suppose that the code will never run in the highlighted issue, in many instances
the tool opens your eyes to "dirty" places in your code.
In the long term, FindBugs has a lot of categories of warnings that inculcate a good
practice for Java Development and hence, is extensively used by giant firms.
REFERENCES:
• http://www.geekviewpoint.com/java/sorting/heapsort
• https://www.methodsandtools.com/tools/findbugs.php
• https://www.eclemma.org/