r1 - 28 Sep 2008 - 16:12:55 - PanitaMeananeatraYou are here: SETEC Wiki >  Knowledge Web  > SoftwareEngineeringCategory > SoftwareTesting > SoftwareTestingTools > Tool_Cobertura

Cobertura Tool

Overview

   Cobertura เป็นหนึ่งใน Code Coverage Tools ชนิด Open Source ที่มีประสิทธิภาพมากในระดับหนึ่ง ซึ่งเหมาะที่จะ Test Code Coverage ในระดับ Unit แบบ White Box จะมีประสิทธิภาพมาก และเหมาะสำหรับ Test Case ที่มีหลากหลายและแตกต่างกัน

Feature

  • สามารถ executed จาก ant srcipt หรือจาก Command Line
  • Instruments Java Byte Code หลังจาก Compiles
  • สามารถ Report ออกมาเป็น ไฟล์ HTML หรือ XML
  • คำนวน Line , Branches Coverage ได้ ตั้งแต่ class , package และ ทั้งโปรแกรม
  • คำนวน McCabe??? cyclomatic code complexity ตั้งแต่ class , package และ ทั้งโปรแกรม
  • สามารถ Report ออกมาเป็น ไฟล์ HTML หรือ XML
  • ใน ไฟล์ HTML report สามารถเรียงลำดับ โดยเรียงจาก class name , เปอร์เซนต์ line covered , เปอร์เซนต์ branches covered , complexity ได้
  • highlight code แต่ละ line ได้ ใน Report

Sample Report

overview.jpg

package.jpg

class.jpg

Installation Cobertura

   1. ให้ Download Library Cobertura จาก http://cobertura.sourceforge.net/download.html เลือกชนิดที่เป็น Binary จะเป็นไฟล์ที่บีบอัดมา หลังจากที่ extract ไฟล์แล้วจะได้ Folder ของ Cobertura ในนั้นจะมี Folder Lib เก็บ Library ต่างๆที่เกี่ยวกับกับการ Test และ Example และ ใน Folder หลักจะมี ไฟล์ cobertura.jar เป็บ Library หลักในการ Test Untitled-1.gif

Quick Start

   ในการ Test ครั้งนี้ เราจะ Test ผ่าน Ant Script มี 3 Step สำคัญๆ ด้วยกันคือ 1. Compile 2. Instrument 3. Report เราจึงต้องเขียน Script เพื่อรัน 3 Stepนี้ตามลำดับ สิ่งที่สำคัญคือการจัด ไฟล์เพื่อให้อยู่ใน Path ที่ถูกต้อง และการ วัด Code Coverage จะเกิดขึ้นได้จากการที่เราสั่ง Test ผ่าน JUnit

   1. จัดเรียง หรือ copy ไฟล์ีที่ต้องการ Test ไว้ใน Folder ดังนี้ คือ ใน Folder Src คือ Foldder ที่เก็บ Source File ไำว้ ที่ 2 ไฟล์คือ Simple.java และ SimpleTest??.java , SimpleTest??.Java คือ คลาสของ JUnit สำหรับ Test ไฟล์ SimpleTest??.Java ซึ่งเรายังเหลืออีก 1 Library คือ JUnit.jar สำหรับเก็บคลาสสำหรับ JUnit ไว้ให้ไป Downloadได้ที่ http://sourceforge.net/project/showfiles.php?group_id=15278&package_id=12472 แล้วนำมาไว้ ที่Folder lib Untitled-2.gif

   2. Config File build.properties ดังนี้เพื่อให้สัมพันธ์กับ การ Test ไฟล์ครั้งนี้ Untitled-3.gif

   3. เข้า Start->run พิมพ์ cmd เพื่อเข้า command line แล้ว ใช้คำสั่ง cd เพื่อไปยัง directory ปัจจุบันที่จะทำการ Test จากนั้นพิมพ์ ant เพื่อทำการ Test Untitled-5.gif

   4.หลังจากที่ Run เสร็จจะได้ Folder ขึ้นมาเพิ่ม คือ classes instrumented reports , classes คือ folder ที่เก็บ class ที่ถูก compile แล้ว instrumented คือfolder ที่เก็บ class ที่ถูก instrument แล้ว และ Report คือ folder ที่เก็บ Report ทั้งหมดในการ Test Code Coverage และการ Test JUnit ครั้งนี้ สามารถเข้าไปดูได้ จากไฟล์ index Untitled-6.gif

Untitled-7.gif

Untitled-8.gif

Reference

  1. Cobertura Test Code Coverage Tool , http://cobertura.sourceforge.net
  2. JUnit , http://www.junit.org
  3. Measure test coverage with Cobertura , http://www-128.ibm.com/developerworks/java/library/j-cobertura/


toggleopenShow attachmentstogglecloseHide attachments
Topic attachments
I Attachment Action Size Date Who Comment
jpgjpg overview.jpg manage 266.3 K 28 Sep 2008 - 15:57 PanitaMeananeatra  
jpgjpg package.jpg manage 273.9 K 28 Sep 2008 - 15:58 PanitaMeananeatra  
jpgjpg class.jpg manage 200.6 K 28 Sep 2008 - 15:58 PanitaMeananeatra  
gifgif Untitled-1.gif manage 12.0 K 28 Sep 2008 - 15:59 PanitaMeananeatra  
gifgif Untitled-2.gif manage 11.5 K 28 Sep 2008 - 16:02 PanitaMeananeatra  
gifgif Untitled-3.gif manage 10.9 K 28 Sep 2008 - 16:02 PanitaMeananeatra  
gifgif Untitled-5.gif manage 22.6 K 28 Sep 2008 - 16:02 PanitaMeananeatra  
gifgif Untitled-6.gif manage 15.5 K 28 Sep 2008 - 16:06 PanitaMeananeatra  
gifgif Untitled-7.gif manage 11.3 K 28 Sep 2008 - 16:06 PanitaMeananeatra  
gifgif Untitled-8.gif manage 10.5 K 28 Sep 2008 - 16:07 PanitaMeananeatra  
Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
 
Powered by SETEC Wiki
Copyright ©2012 by National Electronics and Computer Technology Center, NECTEC.
Ideas, requests, problems regarding SETEC Wiki? Send feedback