Ant/ AntでJunit出来ない

■問題
The for must include junit.jar if not in Ant's own classpath

□みちのり
http://stackoverflow.com/questions/4809695/ant-junit-error-ant-wants-the-junit-jar-in-its-classpath
見ると
To save you the lookup, the options are reproduced below. My preference is option 1.
1. Put both junit.jar and ant-junit.jar in ANT_HOME/lib.
2. Do not put either in ANT_HOME/lib, and instead include their locations in your CLASSPATH environment variable.
3. Add both JARs to your classpath using -lib.
4. Specify the locations of both JARs using a element in a in the build file.
5. Leave ant-junit.jar in its default location in ANT_HOME/lib but include junit.jar in the passed to . (since Ant 1.7)
とある

そもそもAntがinstallされてない
ref: http://www.javadrive.jp/ant/install/
↓行って
http://ant.apache.org/bindownload.cgi
「apache-ant-1.8.3-bin.zip」をclick
適当に展開したらinstall完了
環境変数に
「変数名」に"ANT_HOME"、「変数値」に"C:\{zipを展開したとこ}\apache-ant-1.8.2"を入力してシステム環境変数を追加
「Path」を編集して「%ANT_HOME%\bin;」を追加
とやってみたが関係ない気してきた

■対応
http://ideoplex.com/id/25/ant-and-junit
見ると
you must add junit.jar to your CLASSPATH or copy junit.jar to your Ant library from your JUnit library to enable the integration of JUnit and Ant.
とあるので
build.xml
classpathに
<'pathelement location="C:/IBM/SDPShared/plugins/org.junit4_4.3.1/junit.jar" />
を追加
もしくはrefして先の何処かに<’path path="C:/IBM/SDPShared/plugins/org.junit4_4.3.1/junit.jar"/>詰め込み
したら進んだ◎
と思ったらRAD再起動したら書かんでも行けた
意味不明
けど結果オーライ

□ちなみに
http://d.hatena.ne.jp/uriyuri/20081003/1223025514
によれば
{ANT_HOME}/libにJUnitのjarファイルがない場合なので、jarを入れておくか、Eclipseで実行している場合は、Antのパスに通す
すれば良いようだから
eclipse>window>setting>Ant>runtime>ant home>外部jarでC:/IBM/SDPShared/plugins/org.junit4_4.3.1/junit.jarを追加してみたが
プロジェクトの方もpathいじらんとダメぽいので断念


ref:
Ant JUnit Tasks in en
http://ant.apache.org/manual/Tasks/junit.html
Ant JUnit Tasks in jp
http://www.jajakarta.org/ant/ant-1.5/docs/ant-1.5/j/docs/manual/OptionalTasks/junit.html
Antなサイト
http://www.aksystem.jp/computer/AntPower/AntPower.htm
# colorfulで見やすい
http://works.dgic.co.jp/djwiki/Viewpage.do?pid=@616E74E7B7A8
# simpleで見やすい

tag : ant build xml junit junitreport

2012-03-21 23:51 : __fw__junit : コメント : 0 : トラックバック : 0 :

sample codes for HttpUnit

to instantiate a request by indicating a URL;
-new GetMethodWebRequest(String)

to set local infomation;
-WebRequest#setHeaderField("accept-language","ja")

to get the response(WebResponse) for the WebRequest;
(when the req is redirect, the res gonna be the result of redirect)
-WebConversation#getResponse(WebRequest)

to get the HTML pert of the WebResponse;
-WebResponse#getText()

to get the title of the HTML;
-WebResponse#getTitle(String)

to get the form(WebForm);
-WebResponse#getForms()[1] // for getting the 2nd form.

to get the next screen(WebResponse) by submitting;
-WebFrom#submit()

to get the result screen via a webConversation,
such as WebConversation#getResponse(WebRequest) or WebForm#submit();
-WebConversation#getCurrentPage()

to get or set input values of textBox or other requestParameters;
-WebForm#getParameter(String, String)
-WebForm#setParameter(String, String)

to get or set status of checkBox;
-WebForm#getParameterValue(String) // if there were no check, it returns null.
-WebForm#setCheckbox(String, boolean)

2007-10-03 03:24 : __fw__junit : コメント : 0 : トラックバック : 0 :

cactusStrutsTestCase

□overview
cactusStrutsTestCase
↓↑
HTTP conversation
↓↑
J2EE
↓↑
proxyRedirector
↓↑
cactusStrutsTestCase
↓↑
struts
↓↑
any classes like hogeAction

□to use cactusStrutsTestCase
1.
first, create a testcase extending CactusStrutsTestCase.
2.
delete "setContextDirectory()" if there it is.
the "setContextDirecty()" if for mockStrutsTestCase.
and,
it is no longer cuz contextDirectry gonna be set in server (tomcat/conf/server.xml) in incontainerTest.
3.
delete CONTEXT_ROOT definition as well cuz just no longer.
4.
make sure there is the jndi.datasource difinition in webapp/web-inf/src/system.properties.
ex.
jndi.datasource=java:comp/env/jdbc/seminardb
it is needed for tomcat to get the datasource.
5.
delete the code setting a MockDataSource into ds, the field of ConnectionUtil.
when to use mockStrutsTestCase, tom was not working. thus, the code above was needed to get a datasource.
and,
when to use cactusStrutsTestCase, tom gonna working. so the code is no longer. and by that, the condition, incontainerTest, gonna be satisfied.
2007-10-03 03:09 : __fw__junit : コメント : 0 : トラックバック : 0 :

sample codes of MockStrutsTestCase

to set a contextRoot (only when to use MockStrutsTestCase);
-setCotectDirectory(File)
-use cons.CONTEXT_ROOT for contextRoot path.

to indicate locale of struts-stg file;
-setConfigFile("WEB-INF/struts-config.xml")

to indicate a actionPath;
-setRequestPathInfo("/hoge")

to get a sessionObject;
-getSession()

to execute;
-actionPerform()

to verify forward or forwardPath;
-verifyForward(String)
-verifyForwardPath(String)
2007-10-03 02:51 : __fw__junit : コメント : 0 : トラックバック : 0 :

UT for jsp

when to test JSP,
assume the target JSP as a class of serverSide.
and create a testcase class extending org.apache.cactus.JspTestCase.
the test method gonna be following.
pageContext.include([JSPnoコンテキスト相対パス])
then,
set a redirector as following.
<'servlet>
<'servlet-name>JspRedirector<'/servlet-name>
<'jsp-file>/jspRedirector.jsp<'/jsp-file>
<'/servlet>
<'servlet-mapping>
<'servlet-name>JspRedirector<'/servlet-name>
<'url-pattern>/JspRedirector<'/url-pattern>
<'/servlet-mapping>
2007-10-03 02:45 : __fw__junit : コメント : 0 : トラックバック : 0 :

UT procedure for filter class

when to test filter class,
you need to make a class extending org.apache.cactus.FilterTestCase.
then,
complete web.xml as following.
<'filter>
 <'filter-name>FilterRedirector<'/filter-name>
  <'filter-class>org.apache.cactus.server.FilterTestRedirector<'/filter-class>
 <'/filter>
 <'filter-mapping>
  <'filter-name>FilterRedirector<'/filter-name>
  <'url-pattern>/FilterRedirector<'/url-pattern>
 <'/filter-mapping>
<'/filter>

2007-10-03 02:38 : __fw__junit : コメント : 0 : トラックバック : 0 :

cactus#servletRedirector

□basic cactus operation flow
1. testcase class of clientSide
2. proxyRedirector
3. testcase class of serverSide
4. any serverSide class

□cactus#servletRedirector
as a internal step to use cacus,
you need to map cactus#servletRedirector as a servlet.
sample @web.xml
<'servlet>
<'servlet-name>ServletRedirector<'/servlet-name>
<'servlet-class>org.apache.cactus.server.ServletTestRedirector<'/servlet-class>
<'/servlet>
<'servlet-mapping>
<'servlet-name>ServletRedirector<'/servlet-name>
<'url-pattern>/ServletRedirector<'/url-pattern>
<'/servlet-mapping>

2007-10-03 02:28 : __fw__junit : コメント : 0 : トラックバック : 0 :

jars for cactus

prepare following for using cactus.
aspectjrt-1.1.1.jar
cactus-1.6.1.jar
junit.jar
(commons-logging.jar)
2007-10-03 02:19 : __fw__junit : コメント : 0 : トラックバック : 0 :

UT

□three types for testing
・whiteBox
・grayBox
・blackBox

□whiteBox
プログラムの内部構造を参照し、そのロジックや制御の流れを調べるテスト手法
few types for whiteBox-test
・制御パステスト

□制御パステスト
プログラムの処理経路(開始から終了に至る命令の列)をテストする手法
depends on テストする処理経路の網羅度合い
・C0網羅(命令網羅)
・C1網羅(分岐網羅)
・C2網羅(条件網羅)

□C0網羅
処理経路を構成する全ての命令を最低1回実行するテスト方法

□C1網羅
条件分岐の真と偽の組み合わせをテストする方法

□C2網羅
条件分岐の真と偽の全ての組み合わせをテストする方法

□網羅率(カバレッジ)
全処理経路数のうち、実際にテストした処理経路数の割合
ex
全命令数が100で、このうち50をテストした場合、C0網羅率は50%となる。

□blackBox
テスト対象の仕様や使い方に着眼して、入力値と出力結果の対応関係から、関数やメソッドの振る舞いを調べるテスト
結合テスト以降のテストで用いられる手法
few types for blackBox-test
・同値分割
・境界値分析
・原因結果グラフ・テスト

□同値分割
入力値を有効値の集合と無効値の集合に分け、各集合から代表値を選んでテストする手法

□境界値分析
有効値と無効値の境界地とのその前後の値を選んでテストする手法

□grayBox
メモリへの適当なアクセスやメモリ領域の確保・開放、
プログラムの命令が実行されたかをテスト
テスト対象プログラム内にチェック用のコード(プローブ)を
埋め込んで命令の実行を確保したり、
テスト実施中のメモリ状況を計測してテストする手法

□結合テストの手法
two types
・増加テスト(インクメンタル・テスト)
・一斉テスト(ビックバン・テスト)

□増加テスト
最初にテストしたモジュールに徐々に他のモジュールを結合しながらテストを進める方法。
depends on 結合方法
・トップダウンテスト
 上位モジュールからスタート using stub.
・ボトムアップテスト
 下位モジュールからスタート using driver.
・サンドイッチテスト
 中間のモジュールからスタート

□一斉テスト
全てのモジュールを結合してからテストを実施する方法

ref:
http://itpro.nikkeibp.co.jp/article/COLUMN/20051102/223934/?ST=itarchitect

2007-09-27 04:36 : __fw__junit : コメント : 0 : トラックバック : 0 :

reflectionAPI

□for private field
ClassA obj = new ClassA();
Field f = obj.getClass().getDeclaredField("privateFieldName");
f.setAccessible(true);
f.set(obj, "testValueForPrivateField");
[Type result = (Type)f.get(obj);]

□for private method
Field→Method
getDeclaredField→getDeclaredMethod
set/get→invoke

□attention
if the field is 静的field, use "null" for argument of set/get-method instead of "obj".
consider性能, in usually programming, avoid to use reflection gonna be better.

2007-09-26 08:08 : __fw__junit : コメント : 0 : トラックバック : 0 :

UT

□blackBox & whiteBox
*blackBox;
dont think about inside of program.
just focus on the in/out values and before/after states.
*whiteBox;
think about inside of program.
focus on the each conditions.

□blackBox 値網羅
2 ways for grouping in/out values;
同値分割
限界値分割

□whiteBox パス網羅
4 ways for thinking about conditions;
命令網羅statementCoverage[C0]
―条件(分岐)文以外の全文を最低1回通る。
分岐網羅branchCoverage[C1]
―分岐を含む全文を最低1回通る。(分岐着眼)
条件網羅conditionCoverage[C2]
―分岐を含む全文を最低1回通る。(条件着眼)
複数条件網羅
―分岐を含む全文を最低1回通る。(条件項目着眼)

□other keywords
*driverClass-testTargetClass-stubClass
*2 ways to test when to test the class depends on container;
mockApproach
―sth like driver/stub. use dummy classes instead of real classes.
inContainerApproach
―make sure that other classes is no problem, then use those real classes.
*cactus
the testing fw especially supproting for testing objects in J2EE container.
2007-09-21 00:27 : __fw__junit : コメント : 0 : トラックバック : 0 :

intro to junit: outline_ja

outline
1. itroduction
1.1 what is Junit
keywords: java unit test, framework

1.2 benefits of using Junit
1.2.1 Junit tests allow you to write code faster while increasing quality.
when you write tests using JUnit, youll spend less time debugging, and youll have confidence that changes to your code actually work.
without test, its easy to become paranoid about refactoring or adding new features because you dont know what might break as a result.
1.2.2 JUnit is elegantly simple
should be simple, otherwise theres no incentive to start writing tests in the first place.
1.2.3 Junit tests check their own results and provide immediate feedback.
1.2.4 JUnit tests can be composed into a hierarchy of test suites.
1.2.5 writing Junit tests is inexpensive
1.2.6 junit tests increase the stability of software.
1.2.7 junit tests are developer tests
unlike functional tests, which treat the system as a black box and ensure that the software works as a whole, unit tests are written to test the fundamental building blocks of the system from the inside out.
1.2.8 JUnit tests are written in java
1.2.9 JUnit is free!

2. body
2.1 design of Junit
Junit is designed around two key design patterns: the command pattern and the composite pattern.

atestcase is a command object. any class that contains test methods should subclass the testcase class. a testcase can define any number of public testXXX() methods. when you want to check the expected and actual test results, you invoke a variation of the assert() method.

testcase subclasses that contain multiple testXXX89 mmethods can use the setUp() and tearDown() methods to initialize and release any common objects under test, referred to as the test fixture. each test runs in the context of its own ficture, calling setUp() before and tearDown() agter each test method to ensure there can be no side effects among test runs.

testcase instances can be composed into testsuite hierarchies that automatically invole all the testXXX() methods defined in each testcase instance. a testsuite is a composite of other tests, either testcase instances or other testsuite instances. the composite behavior exhibited by the testsuite allows you assemble test suites of test suites of tests, to an arbitrary depth, and run all the tests automatically and uniformaly to yield a single pass or fail status.


by creating a testsuite in each java package, at various levels of packaging, you can run a testsuite at any level of abstraction.

keep the following things in mind when writing JUnit tests:
*the software does well those things that the tests check.
*thest a little, code a little, test a little, code a little...
*make sure all tests always run at 100%.
run all the all tests in the system at least once per day.
write tests for the areas of code with the highest probablility of breakage.


2007-04-22 15:14 : __fw__junit : コメント : 0 : トラックバック : 0 :
ホーム

search

ad



counter


tag cloud

category cloud