[CUBBY-57] Actionの単体テストがやりやすい仕組みを用意する Created: 2008-01-05  Updated: 2008-01-13  Resolved: 2008-01-13

Status: Closed
Project: Cubby
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0.0-RC1

Type: Improvement Priority: Major
Reporter: agata Assignee: agata
Resolution: Fixed Votes: 0
Labels: None


 Description   

http://jfut.featia.net/diary/20071231.html#p01
ーCubbyTestCaseの準備
-ActionResultから値を取得してAssertできる仕組み

その他便利なものがあれば。



 Comments   
Comment by agata [ 2008-01-13 ]

パスの内部フォワードおよびActionProcesserを使って、
実際のリクエストの処理と同様のプロセスでアクションメソッドを実行できる用にしました。

CubbyTestCase#processAction

Comment by agata [ 2008-01-07 ]

ログインせずにコメントしていました。上記コメントは全てagataです。

Comment by Anonymous [ 2008-01-07 ]

テスト少しプラスしました。Actionのテストの感じはつかめてきました。

アクションメソッドの呼び出しにテストの時のみAOPとかで「ActionContextInitializeInterceptor」のようなものがかませれば初期化の問題は解決しそうな気がします。

Comment by Anonymous [ 2008-01-07 ]

以下のようなコードで通るようになりました。
もう少し簡単に書けるようにしたいところ。

LoginActionTest.java
public class LoginActionTest extends CubbyTestCase {

	private LoginAction action;
	private ActionContext actionContext;
	
    protected void setUp() throws Exception {
        include("app.dicon");
    }
	
	public void testIndex() throws Exception {
		actionContext.initialize(new ActionDefImpl(getComponentDef(LoginAction.class), 
			LoginAction.class.getMethod("index", new Class[0])));
		assertPathEquals(Forward.class, "/todo/login.jsp", action.index());
	}

	public void testLogin() throws Exception {
		actionContext.initialize(new ActionDefImpl(getComponentDef(LoginAction.class), 
			LoginAction.class.getMethod("process", new Class[0])));
		assertPathEquals(Forward.class, "/todo/login.jsp", action.process());
		assertEquals(2, action.getErrors().getFields().size());
		assertTrue(action.getErrors().getFields().containsKey("userId"));
		assertTrue(action.getErrors().getFields().containsKey("password"));
	}

}
Comment by Anonymous [ 2008-01-07 ]

ひとまずcubby-examplesのほうに、CubbyTestCase, HelloActionTest, LoginActionTestをコミットしました。
ActionContextでNullPointerExceptionが発生していますが、まだ未調査です。ActionContextの初期化が必要なのかな。

Generated at Fri Apr 26 04:05:20 JST 2024 using Jira 9.15.0#9150000-sha1:9ead8528714127d8cfabf2446010d7e62c0a195c.