No coverage in 'all classes in scope' in Intellij - intellij-idea

In Intellij IDEA 14.1.5 Community edition, I imported maven to get coverage from jacoco.exec file. Steps followed
right click on imported module.
select Analyze-->Show Converage Data.
provided valid jacoc.exec file and click 'show selected'
Instead of coverage i'm getting error as no coverage in 'all classes in scope'
can anybody suggest what is wrong?

I had the same thing happen to me.
I was able to fix this by going to "Edit Configurations", to the "Code Coverage" tab.
I'm not sure what caused it, but the wrong package namespace was listed there. I updated the entry there and my subsequent test run with code coverage succeeded.

It happens if your test class and class to test are in different package structures.
My test class was in:
com.tools.api
Class to be tested was in:
com.tools.ws
Once I've corrected the pattern as com.tools.* in the code coverage tab, I was able to see coverage results.

I had the same problem and found solution here.
In the Code Coverage tab, define the following options:
Specify the scope to measure code coverage for. Do one of the following:
To specify a class, click the Add Class button.
To specify a package, click the Add Package button.

I was able to fix this issue by:
Open Edit Configurations menu
Click on Modify Options > Coverage settings > Specify classes and packages
In the new box that appears, click on the plus to add a package
Select a high level package from the project

Related

How to locate Intellji IDEA "Generate Test" related code?

Right click on a open Java file, we can get Generate item:
Then click Test and go on, we can generate target Unit Test:
I want to develop a new Intellji IDEA plugin base on upper build-in 'Test generator' feature, I want to check related IDEA source code, I just guss may be in some .jar in com.jetbrains.ideaIC library, and fail to locate it for a long time:
I have no better idea about how to locate the code.
Could you tell me where is the related source code, or how to better locate it?
Thanks for your idea!!!
This is the related package in the source code https://github.com/JetBrains/intellij-community/tree/0e2aa4030ee763c9b0c828f0b5119f4cdcc66f35/java/java-impl/src/com/intellij/testIntegration/createTest

Running a pre-existing .java

I'm switching from Sublime Text 3 to IntelliJ, I had a test.java file on my desktop that I used for small testing but now I am not able run the same in IntelliJ, the problem is it's not showing the file when I select run.
I tried experimenting with different projects created through IntelliJ and understand that I need to set Project to run the code, but again I don't see the file I want.
Here is the project selection screen
Here is what happens when I hit run
See this answer and this document.
You need to configure the content and source roots inside the Java module.
If you right click on test.java and click "Run 'test'", that will attempt to run your main class. Although you may have a NullPointer exception in your code. When you attempt to access a.get(0), the value will return null as there are no Integers in your ArrayList. Also generally class files are named with uppercase first characters. Hope this helps!

Why do I have to run 'rebuild project' for every change in Intellij?

For any change I made to my class, which contains a main() method, I have to run "Build->rebuild project", to make the changes effective. I am afraid my environment or settings have a problem.
Please help.
Please check that you still have Build step in the Before launch setting of the Run/Debug configuration. This is the default, but you could have removed it by accidentally clicking on the — icon.
I think you'll have to repeat this for every JUnit test case.
To alter the behaviour for all test cases:
Run -> Edit Configurations...
In left-hand column, select Templates -> JUnit
Make your changes
Hit OK
I had the same problem and I solved it setting the SDK. You need to go in Project Setting and select the Project tab, as show below
Then you can download a JDK or add a new SDK. Finally, you click on OK and run the code.

List of all errors in project in CLion

CLion 2016.2 helpfully detects potential errors in the file you're editing, which can be seen in the validation bar to the right of the code.
That's just a single file though, is there a way (like a tool window) to get a list of all such warnings in the whole project, or specific parts of it?
Bonus points if it also lists warnings and errors from the compiler, though that's less important, because the compiler output already includes any it found.
Yes, it is possible. The feature you are looking for is called the Inspector.
Do: Find Action... | Inspect Code. It will show a pop-up that will allow you to select the scope: file, whole project, custom, and the Inspection profile (you can choose the type of errors you want to see):
After clicking OK, this is an example of the output, that you can navigate with the mouse or with keyboard shortcuts:
In version 2017.2, I have it under Code | Inspect Code....
You can also right click a folder in Project view and select Inspect Code... there to be able to check only that folder.

Run unit tests in IntelliJ IDEA from multiple modules together

How can I run all tests from two or more IDEA modules at once?
I'm using many modules and it is important to run all of the unit tests often and when I choose more than one folder to run, there's no 'run' option on the context menu any more.
Best way way: (edit after 3 years)
There is even a better way to achieve this. From the JetBrains JUnit Run Configuration docs:
Select menu "Run" → "Edit Configurations...". Click green plus in left top corner and select JUnit.
Select "Test kind" to "Pattern" and enter this regexp exactly as you see it: ^(?!.*IT$).*$ (it starts with caret ^ and ends with dollar $). This regexp says: all tests that do not finish with IT in their name.
Note: The regexp will match against the qualified file names, making it easy to exclude by module/packages as well. If your integration tests are grouped in a package com.me.integrationtests, the regex to match everything not in this package would be ^(?!.*com\.me\.integrationtests.*).*$.
Select "Search for tests" to "In whole project". Working directory should be set to top module working directory (it should be set by default).
Enter a Name for your test like "All Unit tests". I also prefer to mark "Share" option so this configuration won't disappear later. Click Apply and OK.
You can experiment with this regexp to fit your needs.
Original answer:
It is doable, although it's not comfortable.
Select first module, right-click on test/java directory and "Run All Tests". It creates test configuration.
Select "Edit configurations" and check "Share" on newly created configuration so it will be saved.
Select second module, "Run All Tests" on it, and check "Share" on this configuration as well.
In "Before launch" section, click "+" and select "Run Another Configuration" and then select first module's configuration.
This way you run configurations in a sequence and every configuration gets a new tab. Still, better than nothing.
Select all modules, right-click them and choose to run all tests. This will create a configuration called "Whole Project" which you can run again at any time.
I found this better than the accepted answer because this runs the unit tests separately for each module. If your test cases use module-specific resources during its run-time then the accepted answer's best way won't work.
Select all modules
Right click and choose to run all tests
Get a new run configuration
You have to create a "Run Configuration":
Go to the dropdown on the top, at the right hand of the "Make" button and click on it
Select "Edit Configurations"
Now click on the "+" button to add a new run configuration and select JUnit
Then, when configuring the "Run Configuration", you'll find a "Test Kind" dropdown, select "All classes in directory"
Select the directory you want to use as the root, you can choose the top level directory for your project or any of the directories for your modules.
Select the IntelliJ module from where picking up the classpath (it can be the top level project if it has a classpath)
For me both solutions didn't work or didn't work es expected.
For me I have 3 modules. My modules dependencies look like this
Presentation -> Domain -> Data
I just wanted to execute all tests together. So I came up with the 'Across module dependencies' approach
My Settings look like this:
This worked for me for a project with multiple modules.
Create a new JUnit run/debug configuration.
Test kind: 'All in package'
Search for tests: 'Whole project'
You will have to specify a working directory as well.
Another not so obvious case is when code coverage is needed on more than one project. The naive solution would be to select multiple projects and run all unit tests in them at once. As it turns out, unit tests may fail if the classpath changes and IntelliJ has exactly one classpath entry per run configuration. In this case, running unit tests on projects sequentially is actually sufficient. That's because at the end of each run IntelliJ (2017.2.5 Community Edition) asks if the collected coverage should replace or should be added to previously collected coverage stats.
If you use Gradle and have multiple modules, you can do it that way:
make sure IntelliJ is set to use Gradle to run the tests (Settings/Build, Execution, Deployment/Build Tools/Gradle -> Run tests using: Gradle)
right click over a module in the Project navigator and select Run test in [module name]
once done, left click on the configuration that was created in the top toolbar and select Edit Configurations...
in the Run field, simply add more modules just after the first one, for example, if you want to run tests in modules foo, bar and baz: :foo:test :bar:test :baz:test --tests *
rename the configuration, for example Test Foo + Bar + Baz
Now you can just run the configuration to perform the tests you need.