2

I'm facing a very annoying issue while trying to run my project's junit tests inside a remote CI environment.

In my local machine with java 1.8.0_181 and maven 3.5.4 I don't have any problem.

I used to use the two ways bellow to get a test resource:

        String expected = Utils.readStream(new FileInputStream(
            "src/test/resources/testdata/fragment-subdir-absolute-path.txt"));

Using this I'm getting a file not found:

java.io.FileNotFoundException: fragment-subdir-absolute-path.txt (No such file or directory)

And with this:

        String expected = Utils.readStream(new FileInputStream(getClass()
            .getResource("/testdata/fragment-subdir-absolute-path.txt")
            .getPath()));

In this case I'm getting a NPE:

[ERROR] testFragmentFragmentHost Time elapsed: 0.03 s <<< ERROR! java.lang.NullPointerException at org.osgi.service.indexer.impl.IndexerUnitTest.assertFragmentMatch(IndexerUnitTest.java:58) at org.osgi.service.indexer.impl.IndexerUnitTest.assertFragmentMatch(IndexerUnitTest.java:71) at org.osgi.service.indexer.impl.IndexerUnitTest.testFragmentFragmentHost(IndexerUnitTest.java:205)

But anyone is working inside of the remote CIs. The file is not being found.

Cristiano
  • 1,414
  • 15
  • 22
  • Hi Cristiano, can you maybe share a stack trace of the exact error you are facing with? – Matthias Oct 13 '18 at 19:06
  • also - even if i would suspect it does not change anything, another alternative to try would be `Utils.readString(getClass().getResourceAsStream("/testdata/fragment-subdir-absolute-path.txt"))` – Matthias Oct 13 '18 at 19:08
  • Hi @MatthiasHuttar, I've updated the question. thanks – Cristiano Oct 13 '18 at 23:51
  • 1
    If your builds are failing on remote CI services, but not locally, I tend to think that your CI configuration is faulty. Your local machine has some artifacts that get the compilation going, and you are not instructing CI services to fetch them. Try setting up your repository from scratch on a clean system (or a Docker image). – banzaiman Oct 14 '18 at 01:15

1 Answers1

1

Well, embarrassingly, after many many hours, I found where the issue was... :)

The culprit was a copied .gitignore file that contained this:

# Package Files #
 target
 *.jar
 *.txt

Eclipse IDE adds a small interrogation icon on the uncommited files, a small repo icon to the committed ones and just remove the icon from the ignored ones. I just didn't pay attention to those ignored ones.

So, I changed that file to:

# Package Files #
target/*.jar
target/*.txt 

and the mysterious unit tests errors have gone.

thank all for the time...

Cristiano
  • 1,414
  • 15
  • 22