﻿{"id":2635,"date":"2021-09-21T12:19:31","date_gmt":"2021-09-21T12:19:31","guid":{"rendered":"https:\/\/uni.hi.is\/helmut\/?p=2635"},"modified":"2021-09-24T10:17:46","modified_gmt":"2021-09-24T10:17:46","slug":"eclipse-modular-projects-and-junit","status":"publish","type":"post","link":"https:\/\/uni.hi.is\/helmut\/2021\/09\/21\/eclipse-modular-projects-and-junit\/","title":{"rendered":"Eclipse, modular projects and JUnit"},"content":{"rendered":"<p>I (and many others) always had problems making JUnit (as added by Eclipse automatically when creating JUnit test cases) work with modular projects, i.e. projects that use <code class=\"\" data-line=\"\">module-info.java<\/code> files to define dependencies. Finally, I found solutions:<\/p>\n<ul>\n<li>Let the new project wizard not create the module-info.java file -- deleting it afterwards might not be enough as Eclipse did already some modification the the module path settings (OK, trivial) <em>or<\/em><\/li>\n<li>Choose Java \u22648 in settings (i.e. module-info.java ignored -- again: trivial) <em>or<\/em><\/li>\n<li>Apply quick-fixes: in the class containing your JUnit test cases, hover over the org.junit.jupiter.api import and select the quick-fix: \u201cAdd \u2018requires [\u2026]\u2019 to module-info.java\u201d. Then in module-info.java: hover with mouse over the squiggle line (the important point is: clicking on the light bulb does not give any quick-fix, so you need to hover) and do: \u201cMove classpath entry \u2018JUnit5\u2019 to modulepath\u201d. This should fix it!\t<em>or<\/em><\/li>\n<li>Create an Eclipse project with extra src folder (e.g. src-test or use the Maven default structure) that has (via \u201cAllow output folders for source folders\u201d) its own output folder (e.g. bin-test or use the Maven default structure) and that has \u201cContains test sources\u201d toggled to \u201cYes\u201d (in project properties - Java Build Path -Source). The test src folder should then have a more grey-ish icon. Either do this with the New project wizard, or afterwards using project properties. As a result, JUnit is then not part of the modular project anymore. (Has also the advantage that test code is better separated.)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I (and many others) always had problems making JUnit (as added by Eclipse automatically when creating JUnit test cases) work with modular projects, i.e. projects that use module-info.java files to define dependencies. Finally, I found solutions: Let the new project wizard not create the module-info.java file -- deleting it afterwards might not be enough as [&hellip;]<\/p>\n","protected":false},"author":512,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[139469],"tags":[],"class_list":["post-2635","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/posts\/2635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/comments?post=2635"}],"version-history":[{"count":9,"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/posts\/2635\/revisions"}],"predecessor-version":[{"id":2648,"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/posts\/2635\/revisions\/2648"}],"wp:attachment":[{"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/media?parent=2635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/categories?post=2635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/uni.hi.is\/helmut\/wp-json\/wp\/v2\/tags?post=2635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}