0

JUnit 4.10 テスト (forward T) を実行する他のプロジェクトを使用する Java Web アプリケーションを開発しています。T プロジェクトは、コマンド ラインからもテストを完全に実行します。Tomcat 7で実行されているアプリケーションから呼び出すと問題が発生します(他のバージョンは試していません)。initializationError(TestName)、実行可能なメソッドがありません。

テストランナーのコードは次のとおりです。

    public ResultadoPrueba ejecuta() {
        List<String> LClassPathEjecucion = new ArrayList<String>();
        LClassPathEjecucion.addAll(this.LdirectoriosPrueba);
        LClassPathEjecucion.addAll(this.LdirectorioBaseCodigoPractica);
        LClassPathEjecucion.addAll(this.LclassPathNecesarioEjecutor);
        URL[] lClassPath = List2URL(LClassPathEjecucion);
        URLClassLoader cl = new URLClassLoader(lClassPath);
        Class<?>[] cClases = new Class<?>[this.LclasesTest.size()];
        for (int i = 0; i < this.LclasesTest.size(); i++) {
            try {
                cClases[i] = cl.loadClass(this.LclasesTest.get(i).toString());
                log.debug("CLASE " + this.LclasesTest.get(i).toString());
                for (int j = 0; j < cClases[i].getDeclaredMethods().length; j++) {                               
                    log.debug("\t" + cClases[i].getDeclaredMethods()[j].getName());
                    for (int k =0; k<cClases[i].getDeclaredMethods()[j].getAnnotations().length;k++) {
                        log.debug("\t\t"+ cClases[i].getDeclaredMethods()[j].getAnnotations()[k].toString());
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        Request req = Request.classes(cClases);
        JUnitCore jUnitCore = new JUnitCore();
        log.debug("Version de jUnitCore " + jUnitCore.getVersion());
        //jUnitCore.addListener(new TextListener(System.out));
        ListenerPruebas listener = new ListenerPruebas();
        jUnitCore.addListener(listener);
        Result resultadoJUnit = jUnitCore.run(req);
        ResultadoPrueba resultado = new ResultadoPrueba();
        resultado.setResultado(resultadoJUnit);
        resultado.setEjecutados(listener.getResultados());
        resultado.setFallos(listener.getFallos());
        return resultado;
    }
}

juntcore バージョンのログ出力書き込み、メソッド、注釈は、メソッドが書き込まれる順序を除いてまったく同じです。

アイデア?

以下は、Tomcat から呼び出して動作していないテストのサンプルです。

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class JTestDummyTested {

    private DummyTested dummyTested ;

    @Before
    public void startUp(){      
           dummyTested = new DummyTested(1,1);
    }

    @Test
    public void testSuma() {
        assertEquals("1+1 deberian ser 2", 2.0, dummyTested.suma(), 1e-6);
    }

}

これはばかげたjunit 4テストです...

4

0 に答える 0