Intellij test run history - java

What I miss the most in IntelliJ compared to Eclipse is the test run history window. Does anything like this exist in IntelliJ? I didn't find it anywhere so far and have looked a few times at least.
In our project we have ~500 integration test cases which take like 5 minutes to run from IDE. Often I have a situation where for e.g. 5 tests fail in 2-3 different classes. I fix something, that should remove failures from first test suite, rerun it to see if it helped and I must rerun all 500 tests to see which classes contained failures earlier. That is really painful. In eclipse I would just lookup those in test history, repair them also and finally run all 500 to check if nothing new camed up.
Is there a plugin out there or do I miss something obvious?
I use IntelliJ 13.

You can right-click a tab with test results and select the "Pin Tab" option from the context menu. Then further test executions will not overwrite this tab, and you can still refer to it to see which other tests you need to fix.

On the current version of Intellij (2016), you have now a way to reimport older test Result. On the runner tab, click on the button "Import test Results", and select the one you want
EDIT : In the latest version, you have a "Recent Tests" action which allow you to see older test result without a need to open the rest windows. Shortcut Ctrl+Shift+Semicolon

You can also click the "Test History" button to see the old tests result.

Not relevant for Idea 13, but in 2021 this functionality is present in Idea.
https://www.jetbrains.com/help/idea/viewing-and-exploring-test-results.html#view-previous

Yes, given that you are using the IntelliJ test runner (rather than running the tests via maven), you can use the Rerun Failed Tests function.
https://www.jetbrains.com/idea/help/rerunning-tests.html
Edit: based on your comment, can I suggest you run the single test you are working on in "debug" mode, this won't erase the history of your compelte test suite, and you can do that in in combination with the Rerun Failed Tests as needed.

Related

clover#eclipse : tests not relaunched at new build

I am trying to use clover (), a unit-testing plugin for Eclipse, but I wonder about the utility of the option "toggle whether clover instrumentation is performed during compilation for the selected project".
I guessed it has the purpose of launch again the tests and the code coverage after a SAVE option and the following build, but in a dummy project a modification followed by a new build makes the color of the text under test becoming red, but if I modify again the test (this time by setting the test in order to pass) the code coverage stays red, and the tests aren't launched again.
Am I missing something? Is this behavior the correct one? (I mean continuous testing and nearly real time code coverage, at least at each saving).
I use Eclipse Neon, JDK 8 x64 for Windows.

No Code coverage in IntelliJ 2017

I have written some Test methods using Junit and mockito. My tests run fine. However, I am not able to see code coverage.
No matter which option I click on, nothing is shown in code coverage.
I clicked on EDIT to fix configuration seetings displayed in middle of code coverage window on right. This is what I get :
What should I do to get code coverage results ?
This is my folder structure :
To see coverage for production code change the pattern to com.cdk.dmg.asset.
You need to Enable coverage in test folders if you want see coverage in tests (this option is disabled on your screenshot and the pattern is set to record data for tests only, hence no results).
Make sure you have the Coverage plugin enabled! (yes, it's named literally just "Coverage")
Enabling it did it for me.
You don't need to download it from Marketplace, the plugin comes bundled with IntelliJ Idea.
It's my understanding that it should be enabled by default ..but for some reason that wasn't the case for me, so it might as well not be the case for you either.
In IntelliJ IDEA 2018.3 I had to change Test Runner to Gradle to solve the same problem in my Gradle-based project.
File | Settings Ctrl+Alt+S
Build, Execution, Deployment | Build Tools | Gradle | Runner
Run tests using: Gradle Test Runner
Only then I was able to see the coverage.
This is my first answer
you can follow the below steps to enable
Open Visual studio and goto Extensions
Select Manage extension
Search fine code coverage and select to enable
you will get red and green lines on your actual methods that showing that how much you covere the code in Unit test case.
Follow steps

Unit tests terminated in Debug mode

I'm using IntelliJ IDEA 15.0.2 (Community Edition) under Windows 7 and Windows 10 Pro, Gradle 2.9, JDK 1.7.0_65. Operating systems installed as guests under VMware Workstation 11.1.3
I have created Android Gradle application with single empty activity and wanted to check how unit test support works. There is a single unit test module ApplicationTest.java created by IDE, it contains only constructor. Right-clicking on [java] folder I created 'All in Module' JUnit3 test configuration.
Tests complete successfully when I Run them, however fail if I Debug the configuration. Failure reason says 'Terminated' (screenshot, IDEA log) which explained in the documentation as 'Test terminated. This status is assigned to tests that were cancelled by clicking the Stop button'. Just want to confirm that I didn't click the Stop button.
Logcat logs don't report any failures, IDE log reports 2 tests passed too. However problem remains as IntelliJ still reports a termination.
Sometimes I also getting 'Test framework quit unexpectedly' error and no tests succeed.
I've done some research and found similar questions, no real solutions mentioned. Have strong suspicion that this is a configuration issue.
What do I do wrong?
Gabor's suggestion seemed to fix this issue for me. On a Mac (and I presume on a Windows machine, but with a different route to get there) go to Preferences:
From the menu bar at the top Android Studio → Preferences
or
Hit ⌘ and , to jump straight to it.
Then in the menu search box type "instant". Uncheck the box that says "Enable instant run..", which looks like the image below.
That fixed it for me; didn't even need to restart/kill ADB.
It seems to be enabled by default, and I use it often to hot-swap changes during development, so I didn't think to turn it off when running Espresso tests.
In my situation, the problem is solved by setting in the test's run configuration:
Shorten command line -> JAR manifest.
To get rid of unit test problems in debug mode, I deleted all test folders in android studio explorer, then I commented three test implementation lines in build.gradle(module) file. Then I changed the combobox in android studio menu (top of the IDE) from "all in app" to "app".
https://i.stack.imgur.com/alPrS.png
In our case the fix (that may not be required in newer Android-versions) was to:
Open Edit Configuration... for All tests (or what ever you renamed it into).
Switch to Debugger tab.
And finally, in Debug mode combo-box, select the Java option, because:
Although we have lots of Native codes,
Android-studio 3.2.1 (which we were using) does not seem to support debugging both (but Java only mode works fine).

Run JUnit in IntelliJ while ignoring compilation error in an unrelated class?

When running a JUnit test case in IntelliJ it opens up the Make console and shows complication errors in an unrelated class.
Can I run the test case ignoring these errors?
Is there a way to make it not compile the entire project when running the test cases but only those class files required by the test case?
Yes you can.
You can disable the Make before Run.
(The following is written for IntelliJ 14, different versions might have slightly different layouts, but as far as I can remember these options have been the same for a while)
For a single test
Go to "Run" - "Edit Configurations..."
Select the configuration of your test case
In the tab named "Configuration" there is a List "Before Launch" with one entry "Make". Remove that entry.
Confirm with "OK"
For all tests:
If you want to remove this by default for all new test configurations (which might not be a terribly good idea, since then you got to allways build manually when running tests)
Go to "Run" - "Edit Configurations..."
Select "Defaults" in the Tree
Select your Testframework (Junit or TestNG most probably)
In the tab named "Configuration" there is a List "Before Launch" with one entry "Make". Remove that entry.
Confirm with "OK"

Continuous testing with IntelliJ Idea

I'm looking for an IntelliJ IDEA plugin that would run my tests each time I change my code. I looked for such a solution and I found:
Infinitest, which works, but is inconvenient because I need to add the facet to each module, and it opens a new tool window for each module (which means 15 tool windows for me).
Fireworks - didn't work for me, maybe it just doesn't work with IDEA 14 (in its repo I can see that last changes were made in 2009). IntelliJ also reports that it throws exceptions.
There are lots of ways I could run all my tests (including writing a simple script for this), but I'm looking for a tool that would be smart enough to rerun failed tests first, and that would understand module dependencies (so after a change in some module it would run only tests of dependent modules).
I prefer free options, but if there's something paid for a reasonable price, I would accept it as well.
IntelliJ now actually has a Toggle auto-testin the run dialog. Just run a run-configuration and then select Toggle auto-testin the run dialog.
It's not as intelligent as you would have hoped. It just reruns when it detects changes.
I know this is a 3-year-old question but I think it will help people who face the similar problem in future. So I found out a way to enable SBT style auto test execution in IntelliJ studio.
We need to do 2 things to enable auto test execution.
Enabling auto project build - This can be done in settings by going into File -> Settings -> Build, Execution... -> Compiler and selecting "Build Project automatically".
Enabling "Toggle auto-test" in run dialog box
This will start auto testing. Although this works fine, it takes time to build the project even when my project is tiny so for larger projects it will certainly take very long time to complete the build and execute tests.
Reference: Original article which explains these steps
If you are OK running tests which cover a single method chosen by you, you can try this plugin (it is continuos in the sense that you make changes to a method, then click on the method and the plugin will run all the unit tests automatically which cover that method): https://plugins.jetbrains.com/plugin/15063-unit-test-coverage-history-runner
You can use the Intellij Teamcity plugin. Teamcity is a paid product but there is a free version which gives you 20 projects and 3 agents for free .
It has a remote run feature using which you can send in unchecked code to run tests before committing.
It also has options to run failed tests first
Usage instructions for Remote Run

Categories

Resources