In Eclipse, Junit is not picking up files from src/test/resources folder.












0















I have a java, gradle project. My Junit



src/test/java/hello/TestHelloWorld.java 


picks some configurations from



src/test/resources/testdata0010.csv 


the code in Junit to pick this file is



    URL url = this.getClass().getResource("/testdata0010.csv");
File testWsdl = new File(url.getFile());


When I run



gradle test 


this works alright. The Junit is able to pick data from the csv file.



When I run the Junit in Eclipse, i.e. by Shift+Alt+X T, then the Junit breaks with a null pointer exception.



I understand the reason. When I run Junit inside eclipse, it looks for the file in the same folder, does not find it and fails. However, when I run the test using gradle, the csv file is already available in classpath and hence the Junit finds it.



I am looking for some way to have Junit work from within Eclipse.










share|improve this question



























    0















    I have a java, gradle project. My Junit



    src/test/java/hello/TestHelloWorld.java 


    picks some configurations from



    src/test/resources/testdata0010.csv 


    the code in Junit to pick this file is



        URL url = this.getClass().getResource("/testdata0010.csv");
    File testWsdl = new File(url.getFile());


    When I run



    gradle test 


    this works alright. The Junit is able to pick data from the csv file.



    When I run the Junit in Eclipse, i.e. by Shift+Alt+X T, then the Junit breaks with a null pointer exception.



    I understand the reason. When I run Junit inside eclipse, it looks for the file in the same folder, does not find it and fails. However, when I run the test using gradle, the csv file is already available in classpath and hence the Junit finds it.



    I am looking for some way to have Junit work from within Eclipse.










    share|improve this question

























      0












      0








      0








      I have a java, gradle project. My Junit



      src/test/java/hello/TestHelloWorld.java 


      picks some configurations from



      src/test/resources/testdata0010.csv 


      the code in Junit to pick this file is



          URL url = this.getClass().getResource("/testdata0010.csv");
      File testWsdl = new File(url.getFile());


      When I run



      gradle test 


      this works alright. The Junit is able to pick data from the csv file.



      When I run the Junit in Eclipse, i.e. by Shift+Alt+X T, then the Junit breaks with a null pointer exception.



      I understand the reason. When I run Junit inside eclipse, it looks for the file in the same folder, does not find it and fails. However, when I run the test using gradle, the csv file is already available in classpath and hence the Junit finds it.



      I am looking for some way to have Junit work from within Eclipse.










      share|improve this question














      I have a java, gradle project. My Junit



      src/test/java/hello/TestHelloWorld.java 


      picks some configurations from



      src/test/resources/testdata0010.csv 


      the code in Junit to pick this file is



          URL url = this.getClass().getResource("/testdata0010.csv");
      File testWsdl = new File(url.getFile());


      When I run



      gradle test 


      this works alright. The Junit is able to pick data from the csv file.



      When I run the Junit in Eclipse, i.e. by Shift+Alt+X T, then the Junit breaks with a null pointer exception.



      I understand the reason. When I run Junit inside eclipse, it looks for the file in the same folder, does not find it and fails. However, when I run the test using gradle, the csv file is already available in classpath and hence the Junit finds it.



      I am looking for some way to have Junit work from within Eclipse.







      java eclipse gradle






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 15:33









      kaun jovikaun jovi

      8513




      8513
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Ended up being quite simple really. If you include any folder into the buildpath in Eclipse (by rightclicking on the folder and then choose buildpath from the menu) you can solve the problem. Now when I run Junit from within Eclipse, it find the csv file in the buildpath and works well. Care needs to be taken to have this work with gradle or maven, whatever your choice of builder is.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434209%2fin-eclipse-junit-is-not-picking-up-files-from-src-test-resources-folder%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Ended up being quite simple really. If you include any folder into the buildpath in Eclipse (by rightclicking on the folder and then choose buildpath from the menu) you can solve the problem. Now when I run Junit from within Eclipse, it find the csv file in the buildpath and works well. Care needs to be taken to have this work with gradle or maven, whatever your choice of builder is.






            share|improve this answer




























              0














              Ended up being quite simple really. If you include any folder into the buildpath in Eclipse (by rightclicking on the folder and then choose buildpath from the menu) you can solve the problem. Now when I run Junit from within Eclipse, it find the csv file in the buildpath and works well. Care needs to be taken to have this work with gradle or maven, whatever your choice of builder is.






              share|improve this answer


























                0












                0








                0







                Ended up being quite simple really. If you include any folder into the buildpath in Eclipse (by rightclicking on the folder and then choose buildpath from the menu) you can solve the problem. Now when I run Junit from within Eclipse, it find the csv file in the buildpath and works well. Care needs to be taken to have this work with gradle or maven, whatever your choice of builder is.






                share|improve this answer













                Ended up being quite simple really. If you include any folder into the buildpath in Eclipse (by rightclicking on the folder and then choose buildpath from the menu) you can solve the problem. Now when I run Junit from within Eclipse, it find the csv file in the buildpath and works well. Care needs to be taken to have this work with gradle or maven, whatever your choice of builder is.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 8:36









                kaun jovikaun jovi

                8513




                8513
































                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434209%2fin-eclipse-junit-is-not-picking-up-files-from-src-test-resources-folder%23new-answer', 'question_page');
                    }
                    );

                    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







                    Popular posts from this blog

                    Paul Cézanne

                    UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

                    Angular material date-picker (MatDatepicker) auto completes the date on focus out