Why aren't “internal” types in the main source tree visible in my unit tests?











up vote
2
down vote

favorite
1












I've got a Kotlin project in IntelliJ that is structured like this:




  • main/com/foo/Bar.kt

  • test/com/foo/BarTest.kt


where Bar is defined as:



internal class Bar


and BarTest is something like:



class BarTest {
private lateinit var bar: Bar
}


I'm getting compiler errors in IntelliJ on the reference to Bar with the message:




Cannot access 'Bar': it is internal in 'com.foo'




The tests, however, compile and run from the command line (via Gradle).



How can I suppress/remove this error when using IntelliJ?



My setup is:




  • macOS 10.14.1

  • IntelliJ 2018.2.6

  • Kotlin 1.3.10










share|improve this question






















  • There's some debate, but the consensus seems to be that you should only write unit tests for the public API. At the very least, any tests you write against non-public code shouldn't be considered part of your production test suite.
    – Kevin Krumwiede
    Nov 19 at 0:57










  • the thing is i've setup projects like this in the past (i'm looking back at them through GitHub). i recently re-installed everything from my OS on up, so figured maybe i either missed some IntelliJ configuration setting that i had applied before, or that maybe the most recent build has started to employ this behavior.
    – homerman
    Nov 19 at 1:09










  • Technically it is allowed (internal spans main/test in the same module) and there must be a misconfiguration somewhere. Or you are not in the same IntelliJ module for the main/test aspects of your project? Did you create your project using the build.gradle as the source? Maybe recreate your project by opening the build.gradle to see if you fix it. (and check the modules) ... showing your directory structure would help, as well as the build file.
    – Jayson Minard
    Nov 19 at 5:04










  • So, you know it normally works, and only you have enough evidence to know what is different than the normal. Compare it to your previous projects, check modules, see what is different.
    – Jayson Minard
    Nov 19 at 5:06

















up vote
2
down vote

favorite
1












I've got a Kotlin project in IntelliJ that is structured like this:




  • main/com/foo/Bar.kt

  • test/com/foo/BarTest.kt


where Bar is defined as:



internal class Bar


and BarTest is something like:



class BarTest {
private lateinit var bar: Bar
}


I'm getting compiler errors in IntelliJ on the reference to Bar with the message:




Cannot access 'Bar': it is internal in 'com.foo'




The tests, however, compile and run from the command line (via Gradle).



How can I suppress/remove this error when using IntelliJ?



My setup is:




  • macOS 10.14.1

  • IntelliJ 2018.2.6

  • Kotlin 1.3.10










share|improve this question






















  • There's some debate, but the consensus seems to be that you should only write unit tests for the public API. At the very least, any tests you write against non-public code shouldn't be considered part of your production test suite.
    – Kevin Krumwiede
    Nov 19 at 0:57










  • the thing is i've setup projects like this in the past (i'm looking back at them through GitHub). i recently re-installed everything from my OS on up, so figured maybe i either missed some IntelliJ configuration setting that i had applied before, or that maybe the most recent build has started to employ this behavior.
    – homerman
    Nov 19 at 1:09










  • Technically it is allowed (internal spans main/test in the same module) and there must be a misconfiguration somewhere. Or you are not in the same IntelliJ module for the main/test aspects of your project? Did you create your project using the build.gradle as the source? Maybe recreate your project by opening the build.gradle to see if you fix it. (and check the modules) ... showing your directory structure would help, as well as the build file.
    – Jayson Minard
    Nov 19 at 5:04










  • So, you know it normally works, and only you have enough evidence to know what is different than the normal. Compare it to your previous projects, check modules, see what is different.
    – Jayson Minard
    Nov 19 at 5:06















up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I've got a Kotlin project in IntelliJ that is structured like this:




  • main/com/foo/Bar.kt

  • test/com/foo/BarTest.kt


where Bar is defined as:



internal class Bar


and BarTest is something like:



class BarTest {
private lateinit var bar: Bar
}


I'm getting compiler errors in IntelliJ on the reference to Bar with the message:




Cannot access 'Bar': it is internal in 'com.foo'




The tests, however, compile and run from the command line (via Gradle).



How can I suppress/remove this error when using IntelliJ?



My setup is:




  • macOS 10.14.1

  • IntelliJ 2018.2.6

  • Kotlin 1.3.10










share|improve this question













I've got a Kotlin project in IntelliJ that is structured like this:




  • main/com/foo/Bar.kt

  • test/com/foo/BarTest.kt


where Bar is defined as:



internal class Bar


and BarTest is something like:



class BarTest {
private lateinit var bar: Bar
}


I'm getting compiler errors in IntelliJ on the reference to Bar with the message:




Cannot access 'Bar': it is internal in 'com.foo'




The tests, however, compile and run from the command line (via Gradle).



How can I suppress/remove this error when using IntelliJ?



My setup is:




  • macOS 10.14.1

  • IntelliJ 2018.2.6

  • Kotlin 1.3.10







intellij-idea kotlin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 0:50









homerman

1,9871718




1,9871718












  • There's some debate, but the consensus seems to be that you should only write unit tests for the public API. At the very least, any tests you write against non-public code shouldn't be considered part of your production test suite.
    – Kevin Krumwiede
    Nov 19 at 0:57










  • the thing is i've setup projects like this in the past (i'm looking back at them through GitHub). i recently re-installed everything from my OS on up, so figured maybe i either missed some IntelliJ configuration setting that i had applied before, or that maybe the most recent build has started to employ this behavior.
    – homerman
    Nov 19 at 1:09










  • Technically it is allowed (internal spans main/test in the same module) and there must be a misconfiguration somewhere. Or you are not in the same IntelliJ module for the main/test aspects of your project? Did you create your project using the build.gradle as the source? Maybe recreate your project by opening the build.gradle to see if you fix it. (and check the modules) ... showing your directory structure would help, as well as the build file.
    – Jayson Minard
    Nov 19 at 5:04










  • So, you know it normally works, and only you have enough evidence to know what is different than the normal. Compare it to your previous projects, check modules, see what is different.
    – Jayson Minard
    Nov 19 at 5:06




















  • There's some debate, but the consensus seems to be that you should only write unit tests for the public API. At the very least, any tests you write against non-public code shouldn't be considered part of your production test suite.
    – Kevin Krumwiede
    Nov 19 at 0:57










  • the thing is i've setup projects like this in the past (i'm looking back at them through GitHub). i recently re-installed everything from my OS on up, so figured maybe i either missed some IntelliJ configuration setting that i had applied before, or that maybe the most recent build has started to employ this behavior.
    – homerman
    Nov 19 at 1:09










  • Technically it is allowed (internal spans main/test in the same module) and there must be a misconfiguration somewhere. Or you are not in the same IntelliJ module for the main/test aspects of your project? Did you create your project using the build.gradle as the source? Maybe recreate your project by opening the build.gradle to see if you fix it. (and check the modules) ... showing your directory structure would help, as well as the build file.
    – Jayson Minard
    Nov 19 at 5:04










  • So, you know it normally works, and only you have enough evidence to know what is different than the normal. Compare it to your previous projects, check modules, see what is different.
    – Jayson Minard
    Nov 19 at 5:06


















There's some debate, but the consensus seems to be that you should only write unit tests for the public API. At the very least, any tests you write against non-public code shouldn't be considered part of your production test suite.
– Kevin Krumwiede
Nov 19 at 0:57




There's some debate, but the consensus seems to be that you should only write unit tests for the public API. At the very least, any tests you write against non-public code shouldn't be considered part of your production test suite.
– Kevin Krumwiede
Nov 19 at 0:57












the thing is i've setup projects like this in the past (i'm looking back at them through GitHub). i recently re-installed everything from my OS on up, so figured maybe i either missed some IntelliJ configuration setting that i had applied before, or that maybe the most recent build has started to employ this behavior.
– homerman
Nov 19 at 1:09




the thing is i've setup projects like this in the past (i'm looking back at them through GitHub). i recently re-installed everything from my OS on up, so figured maybe i either missed some IntelliJ configuration setting that i had applied before, or that maybe the most recent build has started to employ this behavior.
– homerman
Nov 19 at 1:09












Technically it is allowed (internal spans main/test in the same module) and there must be a misconfiguration somewhere. Or you are not in the same IntelliJ module for the main/test aspects of your project? Did you create your project using the build.gradle as the source? Maybe recreate your project by opening the build.gradle to see if you fix it. (and check the modules) ... showing your directory structure would help, as well as the build file.
– Jayson Minard
Nov 19 at 5:04




Technically it is allowed (internal spans main/test in the same module) and there must be a misconfiguration somewhere. Or you are not in the same IntelliJ module for the main/test aspects of your project? Did you create your project using the build.gradle as the source? Maybe recreate your project by opening the build.gradle to see if you fix it. (and check the modules) ... showing your directory structure would help, as well as the build file.
– Jayson Minard
Nov 19 at 5:04












So, you know it normally works, and only you have enough evidence to know what is different than the normal. Compare it to your previous projects, check modules, see what is different.
– Jayson Minard
Nov 19 at 5:06






So, you know it normally works, and only you have enough evidence to know what is different than the normal. Compare it to your previous projects, check modules, see what is different.
– Jayson Minard
Nov 19 at 5:06














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










I opened up two projects concurrently using the same IntelliJ installation:




  • a former project in which I was able to unit test an internal class located in the main source tree (all within the boundaries of the same IntelliJ module)

  • the current project in which I was unable to reproduce this setup


The fact that IntelliJ still gave no errors in the former setup led me to conclude the issue was not to do with my IntelliJ setup. As @JaysonMinard suggested, I looked at the differences in the Gradle configuration.



The difference was in the current project's top-level settings.gradle, I use the convention of renaming modules, a la:



findProject(':module-blah')?.name = 'blah'


...so as to refer to my Gradle projects by shorter names while having them listed contiguously in my project browser (rather than being scattered around with other files alphabetically). Removing this shortcut restored the behavior I was looking for in my unit tests.






share|improve this answer





















  • interestingly enough... as I mentioned, I removed the line to rename the project via findProject() and IntelliJ doesn't complain about the reference to the internal class from the unit test... and if I restore the findProject() line everything continues to work... ¯_(ツ)_/¯
    – homerman
    Nov 20 at 2:13











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',
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%2f53366990%2fwhy-arent-internal-types-in-the-main-source-tree-visible-in-my-unit-tests%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








up vote
1
down vote



accepted










I opened up two projects concurrently using the same IntelliJ installation:




  • a former project in which I was able to unit test an internal class located in the main source tree (all within the boundaries of the same IntelliJ module)

  • the current project in which I was unable to reproduce this setup


The fact that IntelliJ still gave no errors in the former setup led me to conclude the issue was not to do with my IntelliJ setup. As @JaysonMinard suggested, I looked at the differences in the Gradle configuration.



The difference was in the current project's top-level settings.gradle, I use the convention of renaming modules, a la:



findProject(':module-blah')?.name = 'blah'


...so as to refer to my Gradle projects by shorter names while having them listed contiguously in my project browser (rather than being scattered around with other files alphabetically). Removing this shortcut restored the behavior I was looking for in my unit tests.






share|improve this answer





















  • interestingly enough... as I mentioned, I removed the line to rename the project via findProject() and IntelliJ doesn't complain about the reference to the internal class from the unit test... and if I restore the findProject() line everything continues to work... ¯_(ツ)_/¯
    – homerman
    Nov 20 at 2:13















up vote
1
down vote



accepted










I opened up two projects concurrently using the same IntelliJ installation:




  • a former project in which I was able to unit test an internal class located in the main source tree (all within the boundaries of the same IntelliJ module)

  • the current project in which I was unable to reproduce this setup


The fact that IntelliJ still gave no errors in the former setup led me to conclude the issue was not to do with my IntelliJ setup. As @JaysonMinard suggested, I looked at the differences in the Gradle configuration.



The difference was in the current project's top-level settings.gradle, I use the convention of renaming modules, a la:



findProject(':module-blah')?.name = 'blah'


...so as to refer to my Gradle projects by shorter names while having them listed contiguously in my project browser (rather than being scattered around with other files alphabetically). Removing this shortcut restored the behavior I was looking for in my unit tests.






share|improve this answer





















  • interestingly enough... as I mentioned, I removed the line to rename the project via findProject() and IntelliJ doesn't complain about the reference to the internal class from the unit test... and if I restore the findProject() line everything continues to work... ¯_(ツ)_/¯
    – homerman
    Nov 20 at 2:13













up vote
1
down vote



accepted







up vote
1
down vote



accepted






I opened up two projects concurrently using the same IntelliJ installation:




  • a former project in which I was able to unit test an internal class located in the main source tree (all within the boundaries of the same IntelliJ module)

  • the current project in which I was unable to reproduce this setup


The fact that IntelliJ still gave no errors in the former setup led me to conclude the issue was not to do with my IntelliJ setup. As @JaysonMinard suggested, I looked at the differences in the Gradle configuration.



The difference was in the current project's top-level settings.gradle, I use the convention of renaming modules, a la:



findProject(':module-blah')?.name = 'blah'


...so as to refer to my Gradle projects by shorter names while having them listed contiguously in my project browser (rather than being scattered around with other files alphabetically). Removing this shortcut restored the behavior I was looking for in my unit tests.






share|improve this answer












I opened up two projects concurrently using the same IntelliJ installation:




  • a former project in which I was able to unit test an internal class located in the main source tree (all within the boundaries of the same IntelliJ module)

  • the current project in which I was unable to reproduce this setup


The fact that IntelliJ still gave no errors in the former setup led me to conclude the issue was not to do with my IntelliJ setup. As @JaysonMinard suggested, I looked at the differences in the Gradle configuration.



The difference was in the current project's top-level settings.gradle, I use the convention of renaming modules, a la:



findProject(':module-blah')?.name = 'blah'


...so as to refer to my Gradle projects by shorter names while having them listed contiguously in my project browser (rather than being scattered around with other files alphabetically). Removing this shortcut restored the behavior I was looking for in my unit tests.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 6:09









homerman

1,9871718




1,9871718












  • interestingly enough... as I mentioned, I removed the line to rename the project via findProject() and IntelliJ doesn't complain about the reference to the internal class from the unit test... and if I restore the findProject() line everything continues to work... ¯_(ツ)_/¯
    – homerman
    Nov 20 at 2:13


















  • interestingly enough... as I mentioned, I removed the line to rename the project via findProject() and IntelliJ doesn't complain about the reference to the internal class from the unit test... and if I restore the findProject() line everything continues to work... ¯_(ツ)_/¯
    – homerman
    Nov 20 at 2:13
















interestingly enough... as I mentioned, I removed the line to rename the project via findProject() and IntelliJ doesn't complain about the reference to the internal class from the unit test... and if I restore the findProject() line everything continues to work... ¯_(ツ)_/¯
– homerman
Nov 20 at 2:13




interestingly enough... as I mentioned, I removed the line to rename the project via findProject() and IntelliJ doesn't complain about the reference to the internal class from the unit test... and if I restore the findProject() line everything continues to work... ¯_(ツ)_/¯
– homerman
Nov 20 at 2:13


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53366990%2fwhy-arent-internal-types-in-the-main-source-tree-visible-in-my-unit-tests%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

Costa Masnaga

Fotorealismo

Sidney Franklin