jsunit 알아보기.

ITWeb/개발일반 2011. 11. 9. 13:01

[참고사이트]
- http://www.jsunit.org
http://www.jsunit.net/
http://duwonyi.springnote.com/pages/523087
http://www.javajigi.net/pages/viewpage.action?pageId=4497


[다운로드] 
jsunit2_2.zip



[설치방법]
- plugin 설치 : eclipse_plugin1.0alpha3.zip 압축을 해제 하고 "net.jsunit_1.0.0" 폴더를 eclipse/plugins 폴더에 복사해서 넣는다.
- jsunit2_2.zip 압축을 해제하고 적당한 위치에 옴겨놓는다. ( 예 : C:\development\jsunit )
- C:\development\jsunit 폴더에 logs 폴더 생성

[실행방법]
- eclipse 실행
- 메뉴에서
    Window -> Preferences > JsUnit 으로 이동
- Browser executables 에 IE, FF, Safari 등을 등록
-  Java Project 를 신규로 생성하거나 기존 Web Project이 있으면 활용
- Web root 에  C:\development\jsunit 폴더의 app, css 폴더를 복사해서 넣는다.
- 테스트 코드를 작성할 폴더를 하나 만든다. ( 예 : TestCase )
- TestCase 작성
    jcoverage 때 사용한걸 조금 수정해서 돌려봄

// index.js
function textChange() {

var div = document.getElementById("textLayer");

if ( div.innerText == "Change Text by Click Action" ) {

div.innerText = "Changed Text!!";

}

}

<!-- index.html -->
<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>TestCase1</title>

<script type="text/javascript" src="../app/jsUnitCore.js"></script>

<script type="text/javascript" src="index.js"></script>

<script type="text/javascript">

function testTextChange () {

var div = document.getElementById("textLayer");

textChange();

assertEquals("Changed Text!!", div.innerText);

}

</script>


</head>

<body>

<div id="textLayer" onclick="textChange();">Change Text by Click Action</div>

</body>

</html>


- index.html 파일에서 우클릭 후 run as JsUnit Test Page 실행 그러나 내 eclipse 에서는 동작 하지 않았다 ㅡ.ㅡ;;
- 수동 실행 방법 : 
C:\development\jsunit\testRunner.html 실행 file:/// input text 부분에 index.html 파일 full path 등록 후 Run 버튼 클릭
    (D:\Workspace\jee\jsunit_prototype\UnitTC\index.html)


[TestCase 예제]
- C:\Development\jsunit\tests 폴더에 들어가 보시면 예제 파일들이 많이 있으니 TestCase 작성 시 참고 하시면 됩니다.




: