I started using CUBA Studio v6.10.1 with Plattform v6.10.5 on Windows 7.
IntelliJ Ultimate 2018.3.1 is installed as IDE.
I created an application inside the studio, also added a service and now I wanted to test the service. So I wrote another Unit test inside the core module.
And at that point I found a problem that I cannot solve on my own:
IntelliJ can mark a directory to contain either sources or resources. When I open the IDE from CUBA Studio, the directories are just marked to contain resources. So the java files get copied and not compiled. In IntelliJ, you divide stuff up e.g. src/main/java for sources and src/main/resources for the resources. But CUBA placed everything into one directory (e.g. modules/global/src/ contains xml resources and also a subdirectory entity with java code.)
What went wrong? How to fix it so that I can run the unit tests?
Thank you in advance for your help / pointing me to the correct direction.
We are using Intellij for tests and do not have any problems there. CUBA uses standard Intellij modules layout:
module /
src /
test /
If you generate an empty project, you will see that Studio generates demo test classes in modules/core/test/ directory. Just put your new test there and you will be able to run it using standard Intellij Debug configuration.
If you open this SampleIntegrationTest you will see standard run buttons on the gutter:
Just click on those buttons to run test.
The same applies to other modules, just create test folder in module if needed.
thank you for your reply. From your screens, I see that the source directories are just marked as sources / test sources and I was able to compile everything from inside IntelliJ.
Starting the tests failed with an error that the command line was to long which IntelliJ suggested to solve with 3 possible options (I decided to use a file for the classpath).
But then I ended up with the problem that a component was unable to load a dependency. A component of my solution is using the IMAP addon and I wrote a component, which has a @Inject ImapAPI imapAPI; before a function which handles a NewEmailImapEvent. At this point I thought that it misses some configuration because a config file wasn’t copied to a directory where it is required…
I also searched on this problem and I found, that inside unit tests, instead of Inject I should use AppBeans.get() calls. But the Inject was inside a component and not inside the unit test. I will test if that solves my issues later.
Please note, that all required addons must be declared in your TestContainer:
public class DemoTestContainer extends TestContainer {
public DemoTestContainer() {
super();
appComponents = new ArrayList<>(Arrays.asList(
"com.haulmont.cuba"
// add CUBA premium add-ons here
// and custom app components if any
));