開発メモ

開発用のメモです。

struts2-junit-plugin の使い方

pom.xml

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-junit-plugin</artifactId>
    <version>${struts2.version}</version>
    <scope>test</scope>
</dependency>

test case

import static org.junit.Assert.*;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsJUnit4TestCase;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.seasar.framework.unit.Seasar2;

import com.opensymphony.xwork2.ActionProxy;

public class IndexActionTest extends StrutsJUnit4TestCase<IndexAction> {

    Logger logger = LogManager.getLogger();

    boolean _initialized = false;

    @Ignore
    public void setUp() throws Exception {
        logger.debug("set-up");
        super.setUp();
    }

    @Ignore
    public void tearDown() throws Exception {
        logger.debug("tear-down");
        super.tearDown();
    }

    @Ignore
    public void finishExecution() {
        logger.debug("finish-execution");
        super.finishExecution();
    }

    @Test
    public void testIndex() throws Exception {

        ActionProxy px;
        logger.info(px = getActionProxy("/admin/index.action"));
        assertEquals(px.execute(), IndexAction.INPUT);
    }
}
Twitter: @asahina_alice