Unable to access test resources
up vote
0
down vote
favorite
I have a file testPristineCopy.xlsx in ..srctestresources folder. In my unit test< i try and access it like this:
InputStream testInputStream = this.getClass().getResourceAsStream("/testPristineCopy.xlsx");
I get an error for this line when I tried running the unit test using JUnit. The stack trace is below:
java.lang.NullPointerException
at org.apache.poi.poifs.filesystem.FileMagic.prepareToCheckMagic(FileMagic.java:148)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:175)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:149)
at com.cerner.form_upload.test.ExcelViewSheetTest.extractValuesTest(ExcelViewSheetTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Any idea what the problem is? I need these resources to be accessible for the test cases when they are run on Jenkins.
java unit-testing jenkins junit
add a comment |
up vote
0
down vote
favorite
I have a file testPristineCopy.xlsx in ..srctestresources folder. In my unit test< i try and access it like this:
InputStream testInputStream = this.getClass().getResourceAsStream("/testPristineCopy.xlsx");
I get an error for this line when I tried running the unit test using JUnit. The stack trace is below:
java.lang.NullPointerException
at org.apache.poi.poifs.filesystem.FileMagic.prepareToCheckMagic(FileMagic.java:148)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:175)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:149)
at com.cerner.form_upload.test.ExcelViewSheetTest.extractValuesTest(ExcelViewSheetTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Any idea what the problem is? I need these resources to be accessible for the test cases when they are run on Jenkins.
java unit-testing jenkins junit
Have you addedsrc/test/resources
as source folder?
– Frank Neblung
Nov 19 at 15:13
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a file testPristineCopy.xlsx in ..srctestresources folder. In my unit test< i try and access it like this:
InputStream testInputStream = this.getClass().getResourceAsStream("/testPristineCopy.xlsx");
I get an error for this line when I tried running the unit test using JUnit. The stack trace is below:
java.lang.NullPointerException
at org.apache.poi.poifs.filesystem.FileMagic.prepareToCheckMagic(FileMagic.java:148)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:175)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:149)
at com.cerner.form_upload.test.ExcelViewSheetTest.extractValuesTest(ExcelViewSheetTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Any idea what the problem is? I need these resources to be accessible for the test cases when they are run on Jenkins.
java unit-testing jenkins junit
I have a file testPristineCopy.xlsx in ..srctestresources folder. In my unit test< i try and access it like this:
InputStream testInputStream = this.getClass().getResourceAsStream("/testPristineCopy.xlsx");
I get an error for this line when I tried running the unit test using JUnit. The stack trace is below:
java.lang.NullPointerException
at org.apache.poi.poifs.filesystem.FileMagic.prepareToCheckMagic(FileMagic.java:148)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:175)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:149)
at com.cerner.form_upload.test.ExcelViewSheetTest.extractValuesTest(ExcelViewSheetTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Any idea what the problem is? I need these resources to be accessible for the test cases when they are run on Jenkins.
java unit-testing jenkins junit
java unit-testing jenkins junit
asked Nov 19 at 10:44
user3377812
135
135
Have you addedsrc/test/resources
as source folder?
– Frank Neblung
Nov 19 at 15:13
add a comment |
Have you addedsrc/test/resources
as source folder?
– Frank Neblung
Nov 19 at 15:13
Have you added
src/test/resources
as source folder?– Frank Neblung
Nov 19 at 15:13
Have you added
src/test/resources
as source folder?– Frank Neblung
Nov 19 at 15:13
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can use the relative path to access any resource file under src/test/resources folder. Something like this.
InputStream testInputStream = new FileInputStream(new File("src/test/resources/testPristineCopy.xlsx"));
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can use the relative path to access any resource file under src/test/resources folder. Something like this.
InputStream testInputStream = new FileInputStream(new File("src/test/resources/testPristineCopy.xlsx"));
add a comment |
up vote
0
down vote
You can use the relative path to access any resource file under src/test/resources folder. Something like this.
InputStream testInputStream = new FileInputStream(new File("src/test/resources/testPristineCopy.xlsx"));
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use the relative path to access any resource file under src/test/resources folder. Something like this.
InputStream testInputStream = new FileInputStream(new File("src/test/resources/testPristineCopy.xlsx"));
You can use the relative path to access any resource file under src/test/resources folder. Something like this.
InputStream testInputStream = new FileInputStream(new File("src/test/resources/testPristineCopy.xlsx"));
answered Nov 19 at 15:03
lrathod
359212
359212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372914%2funable-to-access-test-resources%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Have you added
src/test/resources
as source folder?– Frank Neblung
Nov 19 at 15:13