0

I'm doing unit testing and for that I need to read from excel files. The files are located in the folder: module/test/resource/click/T001.xlsx
The test class is in the directory module/test/java/validation/readers/spreadsheets/PlanilhaReaderTest.java and the class I test in src/main/java/validation/readers/spreadsheets/PlanilhaReader.java

How do I open the directory where it is located my files ( ../test/resource )?

My test

@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);
    }

Output
Path: file:/home/daniela.morais/Development/git/myProject/myModule/target/test-classes/click/T001.xlsx

Daniela Morais
  • 2,125
  • 7
  • 28
  • 49
  • Are you working with Eclipse - use the context menu to make the module/test/resource folder a part of the build path (..as source folder). Then everything inside this folder will automatically copied to target/test-classes and should be found. – swinkler May 27 '15 at 16:23
  • I working with intelliJ – Daniela Morais May 27 '15 at 16:24
  • Don't have IntelliJ installed here. Can you check this - http://stackoverflow.com/questions/21722657/how-to-mark-package-as-a-resource-folder - in the green section of the screenshot under "Test Source Folders also your /module/test/resource has to be. – swinkler May 27 '15 at 16:27
  • This solved my problem, just takes the directory path: `oknok.validacao.entities.Planilha planilha = new Planilha().setPath(PlanilhaReader.class.getClass().getResource("/click/T001.xlsx").getPath());` – Daniela Morais May 27 '15 at 17:20

0 Answers0