在测试中,如何在资源目录中打开文件?

时间:2015-05-27 16:18:27

标签: java unit-testing

我正在进行单元测试,为此我需要从excel文件中读取。这些文件位于文件夹中:module/test/resource/click/T001.xlsx
测试类位于module/test/java/validation/readers/spreadsheets/PlanilhaReaderTest.java目录中,而I类测试位于src/main/java/validation/readers/spreadsheets/PlanilhaReader.java

如何打开目录所在文件(../ test/resource)?

我的测试

@Test(expected = InternalServerErrorException.class)
    public void testReadMetadados_invalidPlanilha_invalidFormat() throws Exception {
        oknok.validacao.entities.Planilha planilha = new Planilha().setPath(String.valueOf(PlanilhaReader.class.getClass().getResource("/click/T001.xlsx")));
        Log.info(this, "Path: " + planilha.getPath());
        planilhaReader.readMetadados(planilha);
    }

输出
路径:文件:/home/daniela.morais/Development/git/myProject/myModule/ target / test-classes / 点击/ T001.xlsx

0 个答案:

没有答案