07.01.2013 Views

Lecture Notes in Computer Science 3472

Lecture Notes in Computer Science 3472

Lecture Notes in Computer Science 3472

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

**** BluetoothUnitTest.java ***/<br />

(0) import junit.framework.TestCase;<br />

(1) import BluetoothRoam<strong>in</strong>g;<br />

(2) public class SlaveRoam<strong>in</strong>gListTest extends TestCase {<br />

(3) private SlaveRoam<strong>in</strong>gList RList;<br />

(4) private SlaveRoam<strong>in</strong>gList emptyList;<br />

(5) protected void setUp () {<br />

(6) RList = new SlaveRoam<strong>in</strong>gList ([”M1”,”M2”,”M3”]);<br />

(7) emptyList = new SlaveRoam<strong>in</strong>gList ([ ]);<br />

(8) }<br />

(9) public void testIsNull () {<br />

(10) assertTrue (emptyList.isNull ());<br />

(11) }<br />

(12) public void testSearchNextElement () {<br />

(13) Str<strong>in</strong>g element = RList.nextElement ();<br />

(14) assertTrue (element.equals(new Str<strong>in</strong>g (”M1”)));<br />

(15) }<br />

17 UML 2.0 Test<strong>in</strong>g Profile 515<br />

(16) public static Test suite () {<br />

(17) TestSuite suite = new TestSuite ();<br />

(18) suite.adddTest (new SearchNewMasterTest (”testSearchNextElement”));<br />

(19) suite.addTest (new SearchNewMasterTest (”testIsNull”));<br />

(20) return suite;<br />

(21) }<br />

(22) public static void ma<strong>in</strong> (Str<strong>in</strong>g args[ ]) {<br />

(23) junit.textui.TestRunner.run (suite());<br />

(24) }<br />

(25) }<br />

Fig. 17.14. JUnit Code<br />

Figure 17.13b) shows a Sequence Diagram of the test case testSearchNextElement(),<br />

which returns a verdict as its result. The test case starts with the test<br />

context <strong>in</strong>stance SlaveRoam<strong>in</strong>gListTest and firstly creates two <strong>in</strong>stances RList and<br />

emptyList of type SlaveRoam<strong>in</strong>gList. RList has the entries [”M1”,”M2”,”M3”] mean<strong>in</strong>g<br />

that whenever the l<strong>in</strong>k quality between the current master and the slave<br />

becomes bad, Master M1 should be the successory master, otherwise Master M2<br />

and M3, respectively. emptyList has no entries. It is created to check whether<br />

the method recognizes an empty list and thus send warn<strong>in</strong>g messages to the<br />

environment.<br />

After the two roam<strong>in</strong>g list <strong>in</strong>stances are created, RList is asked to provide the<br />

next element of the roam<strong>in</strong>g list. Accord<strong>in</strong>g to the order<strong>in</strong>g of the roam<strong>in</strong>g list,<br />

the return value is M1. After that, the test is f<strong>in</strong>ished and a verdict of value pass

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!