注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

星期五

明天不上班

 
 
 

日志

 
 
关于我

一个特立独行的Java程序员,比较宅,上上网,写博客,听音乐,看电影。

网易考拉推荐

JsUnit使用(2)  

2013-07-30 19:24:22|  分类: Javascript |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
testRunner.html支持url参数
testPage参数 指定要测试的Test Page
例如:
file:///C:/Users/IBM_ADMIN/Desktop/jsunit/testRunner.html?testPage=C:/Users/IBM_ADMIN/Desktop/jsunit/tdd/tracing.html

autoRun参数 让TestPage 直接运行
file:///C:/Users/IBM_ADMIN/Desktop/jsunit/testRunner.html?testPage=C:/Users/IBM_ADMIN/Desktop/jsunit/tdd/tracing.html&
autoRun=true

debug 参数 (FireFox22 和IE8 未生效?)
file:///C:/Users/IBM_ADMIN/Desktop/jsunit/testRunner.html?testPage=C:/Users/IBM_ADMIN/Desktop/jsunit/tdd/tracing.html&autoRun=true&debug

如何搭建JsUnit服务器
  • 安装 apache ant
  • 修改JsUnit build.xml
  • 启动JsUnit服务器,开始测试。
1.安装ant
下载: http://ant.apache.org/ , 加压文件, 配置环境变量,测试
JsUnit使用(2) - 星期五 - 星期五
 
2.修改JsUnit build.xml
browserFileNames:浏览器地址;多个可以用逗号隔开; 
closeBrowsersAfterTestRuns:执行测试后,是否关闭浏览器;默认true 
logsDirectory:日志存放目录 
url:测试文件地址;如: file:///c:/jsunit/testRunner.html?testPage=c:/jsunit/tests/jsUnitTestSuite.html 

在控制台下进入相关目录运行ant standalone_test 即可。 
standalone_test:  是在单机上行运行测试; 
distributed_test:是分布式远程测试;

<?xml version="1.0" encoding="utf-8"?>

<project name="JsUnit" default="standalone_test" basedir=".">

<!--
The following are the properties used to configure JsUnit. You need to provide values for the mandatory properties.
See the documentation at http://www.jsunit.net for more information.
-->

<property
name="browserFileNames"
value="C:\Program Files (x86)\Internet Explorer\iexplore.exe,C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
description="browserFileNames is a comma-separated list of browsers in which to run tests when StandaloneTest is invoked on this host. Each value can be a semi-colon separated list, with the second value being the program to run to shut down the browser and the third value being the display name of the browser. The second and third values are optional. For a JsUnit Server, this is a mandatory property. For example: 'c:\program files\internet explorer\iexplore.exe;c:\program files\killie.bat;Internet Explorer 6.0,c:\program files\netscape\netscape7.1\netscp.exe,c:\program files\Opera\runopera.bat'"
/>

<property
id="closeBrowsersAfterTestRuns"
name="closeBrowsersAfterTestRuns"
value="true"
description="closeBrowsersAfterTestRuns determines whether to attempt to close browsers after test runs. This is not a mandatory property. The default is true. For example: 'true'"
/>

<property
id="description"
name="description"
value="This is a JsUnit Test"
description="description is a human-readable description of a standard or aggregate server. This is not a mandatory property. The default is blank. For example: 'This is our Mac - it's only running Safari right now'"
/>

<property
id="ignoreUnresponsiveRemoteMachines"
name="ignoreUnresponsiveRemoteMachines"
value=""
description="ignoreUnresponsiveRemoteMachines is a property used only by the JsUnit Aggregate Server and the distributed_test target. Its value is whether to ignore a remote machine that does not respond. If true, test runs will be green even if one or more remote machines fail to respond; if false, an unresponsive remote machine results in a failure. This is not a mandatory property. Its default is false. For example: 'true'"
/>

<property
id="logsDirectory"
name="logsDirectory"
value="C:\Users\XXX_ADMIN\Desktop\jsunit\tdd\logs"
description="logsDirectory is the directory in which the JsUnitStandardServer stores the XML logs produced from tests run. It can be specified relative to the working directory. This is not a mandatory property. If not specified, the directory called 'logs' inside resourceBase is assumed. For example: 'c:\jsunit\java\logs'"
/>

<property
id="port"
name="port"
value="8080"
description="port is the port on which the JsUnitStandardServer runs. This is not a mandatory property. If not specified, 8080 is assumed. For exapmle: '8080'"
/>

<property
id="remoteMachineURLs"
name="remoteMachineURLs"
value="http://localhost:8080"
description="remoteMachineURLs is a property used only by the JsUnit Aggregate Server and the distributed_test target. Its value is the list of URLs of remote machines to which a request to run tests will be sent. For example: 'http://machine1.company.com:8080,http://localhost:8080,http://192.168.1.200:9090'"
/>

<property
id="resourceBase"
name="resourceBase"
value="C:\Users\IBM_ADMIN\Desktop\jsunit"
description="resourceBase is the directory that the JsUnitStandardServer considers to be its document root. It can be specified relative to the working directory. This is not a mandatory property. If not specified, the working directory is assumed. For example: 'c:\jsunit'"
/>

<property
id="timeoutSeconds"
name="timeoutSeconds"
value=""
description="timeoutSeconds is the number of seconds to wait before timing out a browser during a test run. This is not a mandatory property. If not specified, 60 is assumed. For example: '60'"
/>

<property
id="url"
name="url"
value="file:///C:/Users/IBM_ADMIN/Desktop/jsunit/testRunner.html?testPage=C:/Users/IBM_ADMIN/Desktop/jsunit/tdd/tracing.html"
description="url is the URL (HTTP or file protocol) to open in the browser. For a JsUnit Server, this is a mandatory property for a test run if the server is not passed the 'url' parameter. For example: 'http://myhost.mycompany.com:8080/jsunit/testRunner.html?testPage=http://myhost.mycompany.com:8080/jsunit/tests/jsUnitTestSuite.html'"
/>

<property name="bin" location="java/bin"/>
<property name="lib" location="java/lib"/>
<property name="loggingPropertiesFile" location="logging.properties"/>

<path id="classpath">
<fileset dir="${lib}">
<include name="*.jar"/>
<include name="*/*.jar"/>
</fileset>
<fileset dir="${bin}">
<include name="jsunit.jar"/>
</fileset>
</path>

<target name="start_server" description="Starts a JsUnit Server">
<java fork="true" classname="net.jsunit.JsUnitServer">
<classpath refid="classpath"/>
<sysproperty key="java.util.logging.config.file" value="${loggingPropertiesFile}"/>
<sysproperty key="browserFileNames" value="${browserFileNames}"/>
<sysproperty key="closeBrowsersAfterTestRuns" value="${closeBrowsersAfterTestRuns}"/>
<sysproperty key="description" value="${description}"/>
<sysproperty key="logsDirectory" value="${logsDirectory}"/>
<sysproperty key="port" value="${port}"/>
<sysproperty key="resourceBase" value="${resourceBase}"/>
<sysproperty key="timeoutSeconds" value="${timeoutSeconds}"/>
<sysproperty key="url" value="${url}"/>
</java>
</target>

<target name="stop_server" description="Stops the JsUnit Server">
<java fork="true" classname="org.mortbay.stop.Main" failonerror="true">
<classpath refid="classpath"/>
</java>
</target>

<target name="standalone_test" description="Runs tests on the local machine">
<junit showoutput="true" haltonerror="true" haltonfailure="true">
<formatter type="plain" usefile="false"/>
<classpath refid="classpath"/>
<sysproperty key="java.util.logging.config.file" value="${loggingPropertiesFile}"/>
<sysproperty key="browserFileNames" value="${browserFileNames}"/>
<sysproperty key="description" value="${description}"/>
<sysproperty key="closeBrowsersAfterTestRuns" value="${closeBrowsersAfterTestRuns}"/>
<sysproperty key="logsDirectory" value="${logsDirectory}"/>
<sysproperty key="port" value="${port}"/>
<sysproperty key="resourceBase" value="${resourceBase}"/>
<sysproperty key="timeoutSeconds" value="${timeoutSeconds}"/>
<sysproperty key="url" value="${url}"/>
<test name="net.jsunit.StandaloneTest"/>
</junit>
</target>

<target name="distributed_test" description="Runs tests on the remote machines">
<junit showoutput="true" haltonerror="true" haltonfailure="true">
<formatter type="plain" usefile="false"/>
<classpath refid="classpath"/>
<sysproperty key="java.util.logging.config.file" value="${loggingPropertiesFile}"/>
<sysproperty key="browserFileNames" value="${browserFileNames}"/>
<sysproperty key="description" value="${description}"/>
<sysproperty key="ignoreUnresponsiveRemoteMachines" value="${ignoreUnresponsiveRemoteMachines}"/>
<sysproperty key="logsDirectory" value="${logsDirectory}"/>
<sysproperty key="port" value="${port}"/>
<sysproperty key="remoteMachineURLs" value="${remoteMachineURLs}"/>
<sysproperty key="resourceBase" value="${resourceBase}"/>
<sysproperty key="url" value="${url}"/>
<test name="net.jsunit.DistributedTest"/>
</junit>
</target>

</project>

3.测试,切换到JsUnit目录,运行ant命令
JsUnit使用(2) - 星期五 - 星期五
 
生成的log文件
JsUnit使用(2) - 星期五 - 星期五
  评论这张
 
阅读(420)| 评论(0)
推荐

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017