Computer Science

studystudent
MyAssignment2.docx

This exercise helps you build a test case with JUnit version 4.x, make you familiar with Junit original framework and test statistics using eclipse.

1. Build the application

· Build an application, which sorts 7 random string, comma delimitated, names using binary tree (e.g. String input = “Peggy, John, Steve, Albert, .......” ;)

· Use the following methods for your application

· ▪ populateTree //This method populates the tree

· ▪ traverseTree //This method displays sorted name

· ▪ countNode //This method counts all the nodes in the tree

· ▪ counLeaf // This method counts leafs in the tree

· Binary

· ▪ This is a tree which each node has two children

· ▪ Left node is smaller than the parent and right node is greater

than the parent

· ▪ Example

1. This is an example which shows how to build binary

tree from this array of integers: [7, 5, 4, 3, 6, 1, 2]

2. In your assignment, you should use names (characters)

tree

instead of numbers. o 7 o5 o46 o3

o1

-------→root

o2 2. Build JUnit 4.x test case to test all methods of the application

• Class BinaryTreeTestCase { ▪setup ()

▪testXXX () // one method for each application function ▪teardown () ▪suite () ▪main ()

•}

3. Build a suite of test cases to test all methods of the application

4. Build the eclipse project, create jar, and e-mail jar as described in the

Lab Process.

1. Build your application for test as follow

· Node class public class Node {

//instance variables //constructor // methods

}

· BinaryTreeApp Class

public class BinaryTreeApp { //application methods populateTree (....) traverseTree (....)

countNode (....)

counLeaf (....) }

2. Build the JUnit Test case as described in Unit-2 and 3.

• Your test case template would be like this public class BinaryTreeTestCase { // instance/class variables

// constructor // test methods

protected void setup () throws Exception { } public void testPopulateTree () throws Exception { } // ............... other methods ...................... protected void tearDown () throws Exception { }

public static Test suite () { } public static void main (..) {

//build TestResult object and display how many

// testcases passed AND failed with error }

}

3. Build and run the eclipse project

· Create a java project and name it “testbinarytree”

· Create a package under the project and name it

· (e.g. susan. junit.assignment2.binarytree)

· Compile and run the test case as

i. “JUnit Test”

ii. “Java Application”