0

I'm trying to use PigUnit with Maven. In Maven, my pig scripts are located under the module's root directory at <module>/src/main/pig/<scriptName>.pig

All the PigUnit test tutorials either code the absolute url of the pig script (which obviously won't work when the build runs anywhere but my machine) or the relative path and it just "magically" works. But when I put in either the script name directly or src/main/pig/<scriptName>.pig to PigTest, the script can't be found when running mvn test.

Test with line (using scala + scalatest):

val pigTest = new PigTest("src/main/pig/calcProductVectors.pig", args)

Results in:

- Script does something *** FAILED ***
  java.io.FileNotFoundException: src/main/pig/calcProductVectors.pig (No such file or directory)
  at java.io.FileInputStream.open0(Native Method)
  at java.io.FileInputStream.open(FileInputStream.java:195)
  at java.io.FileInputStream.<init>(FileInputStream.java:138)
  at org.apache.pig.pigunit.PigTest.readFile(PigTest.java:296)
  at org.apache.pig.pigunit.PigTest.readFile(PigTest.java:292)

How do I get src/main/pig to be on the path when mvn test runs?

Adair
  • 1,697
  • 18
  • 22

1 Answers1

0

Okay, so I found some tests in our Java projects that just added the pig directory to project.build.testResources in maven:

<testResources>
  <testResource>
    <!-- Pig is being included in test/resource so that we can access it with PigUnit -->
    <directory>src/main/pig</directory>
    <filtering>true</filtering>
  </testResource>
  <testResource>
    <directory>src/test/resources</directory>
    <filtering>true</filtering>
  </testResource>
</testResources>

Then the JUnit tests would pass src/main/pig/<scriptName>.pig to PigTest.

This didn't work in my project, not sure if it's because of scalatest or something else. I could see the contents of the directory getting copied to <module>/target/test-classes, but they still weren't found either with their direct name (which seems like it would make more sense because they were copied without the src/main/pig part) or that whole path which was working for the Java projects.

Eventually from this answer, I found out where the tests were running from on the file system, and it was just the module name, so I adjusted the path like so and it worked:

val pigTest = new PigTest("<module>/src/main/pig/calcProductVectors.pig", args)
Adair
  • 1,697
  • 18
  • 22