Intellij Idea How to show tests covering line - unit-testing

I'm using IDEA in order to analyze our code coverage.
I can see that some lines were called N number of times. But I also want to know which test caused that line call.
I see the appropriate button "Show tests covering line", but this button is disabled for all of the lines.
So what is the reason of that behavior and is it possible to force IDEA to show tests which called a particular line of the code

From the docs:
For JUnit tests, you can open the test that covers a line in a separate dialog. To do so, click the the Show Tests Covering Line icon in the popup. To be able to use this feature, enable the Tracing mode and Track per test coverage options for the current run/debug configuration in the Code Coverage area. For more information, refer to Set coverage in run configurations.
The Set Coverage in run configurations page details how to do this for your IDE version. Newer versions will have a Coverage Tab, older versions will not. The set up instructions for both are detailed in this page.

Related

IntelliJ Idea - Jump to test code of covered code?

Is there a way to jump to test code that is already in place? for example, let's say I have a method and some of the code is 'covered' after I run with coverage. How would I be able to tell what unit tests are covering this code without manually checking each test?
#jonrsharpe gave me the resources to answer this question, so thanks!
check this out here, it will give you all the information you will need: info on viewing code coverage results
this feature can be accessed by clicking on the coloured line by your code and clicking on a button called 'show tests covering line' this option is only available if you enable 'tracing' for your code coverage. this option can be enabled from configuring the test task. info on this bit here: info on configuring run profiles for code coverage

Running Isolated Tests Without Relying on Terminal? IntelliJ IDEA

I understand that I should use the sure-fire plugin for unit tests, and failsafe for integration. I can run unit tests with mvn test and integration tests with mvn verify but this annoys me for 2 reasons:
I'd prefer to be able to select any test class (or method in that class) and run it individually by a simple click, rather than typing it into terminal every time.
The terminal returns the test results in ugly black/white paragraphs, requiring me to sift through them. I'd much prefer to have the results returned in a visually organized manner, similar to if I right-clicked on the test class in IntelliJ and click 'RunDemoTest`. This produces:
I find the error results much easier to sift through, for example it shows red/green #Test results on the left, and on the right it cleanly organizes the error into
Expected : 3
Actual :1
I'm sure there are advantages to using terminal for automated test runs later into production, but during development I don't find the terminal conducive to my tinkering.
How do I benefit from IntelliJ's visual feedback of test results, while simultaneously ensuring unit & integration tests are run separately, and preserving my freedom to pick and choose which test classes and test methods I can run at any time?
I'm assuming I can't have my cake and eat it too. Please explain.
If you are using the IntelliJ view "Maven Projects" you can very easy toggle on/off the exection of maven integrated tests.
Via "Run/Debug Configurations" you can create test executions that match your reqirement for a comfortable UI.
After these steps, there is a new entry in the drop down list "Run/Debug configurations". When you start the new JUnit Test configuration, the defined tests are executed and the results are presented exactly in the same manner as the screenshot in your question.
The options in my second screenshot allow a very flexible definition of the scope. You don't have go to every java file and click on the green arrows in the editor view.
This configuration isn't related to any maven configuration, and you can use them at any time in your coding process.

how to check code coverage of specific controller in mvc?

I want to know the steps for analyzing code coverage of any specific controller.
I am working on ASP.NET MVC4 with Visual Studio 2012 and TFS setup.
I know that with can analyze code coverage of all of the controllers from test explorer window "Analyze code coverage for all controller" option.
But i want to check the code coverage of any one controller.
First you can group them by the Class Name in the Test Explorer window. Then find the specific Controller you need the Code Coverage. Then Right Click on the at Controller, and select "Analyze Code Coverage For Selected Tests". This would produce the Code Coverage for the specific Controller you selected. Note that you see all other Controllers/Types have been instrumented in the Code Coverage Result window, however they don't have any coverage result. It would just say Covered (Blocks) = 0.

Test settings for unit tests on Team Foundation Server

I am using MSTest and running unit tests on Team Foundation Server. I am doing wildcard test execution as here; also see image.
I want to use an arbitrary test settings file for one specific dll / test assembly (let's call it foo.dll) and not use any test settings file/use the default settings for every other dll that is grabbed by the wildcard. What is the best way to do that?
I have an image that might help illustrate:
(The above is an image of the screen at Process tab-->Basic-->Automated Tests-->Test Assembly, within the Team Foundation Build template.)
With the standard, out of the box process templates you can't do what you're after. You can't wildcard assemblies and exclude some at the same time, and you can't attach a test settings file for just some assemblies. The reason being that under the hood it's doing a single test run and the settings apply for the whole test run.
As an idea, you could copy and customize the build process template, and specifically alter the section relating to running tests to do what you need. Add a second test run to it for example so you can do one set of tests without the run settings and another run with them. For both test runs use the wildcard specification and then use the criteria/arguments tab to decide which tests to run. In the DLL you want to exclude from the first run, tag the tests with an attribute and ignore those in your first test run. For the second include just tests with that attribute.

How to run single test case in Xcode?

I know it is best practice to run all unit test cases after any change to make sure not breaking anything. However, some times, e.g. debugging, I really want to run only one single test case. It seems Xcode doesn't provide any such feature in UI, while other testing framework such as JUnit has such features.
Is there any workaround to have only one testcase run in Xcode?
P.S. most of my test cases are logic tests. So, they are not run in iPhone device.
Xcode 4 now have this feature. Simply create a "run scheme"  that has the test cases that you want to run.
Open menu "Product|Edit Scheme..."
Click on "Edit..."
In the left pane, expand the "Test" section.
In the right pane, expand the test bundle and uncheck the test cases you don't need to run.
⌃+⌥+⌘+U
You can also use the keyboard short cut of Control-Option-Command-U
Expert taken from Apple Documentation
Product > Perform Action > Test . This dynamic menu item senses the current test method in which the editing insertion point is positioned when you’re editing a test method and allows you to run that test with a keyboard shortcut. The command’s name adapts to show the test it will run, for instance, Product > Perform Action > Test testAddition. The keyboard shortcut is Control-Option-Command-U.
I'm sure that no one missed the release of Xcode 5 and its ability to easily run a single test case, but adding this answer just for completeness.
In Xcode 5 you can run a single test case by clicking the little play button that you can find next to the test in the test navigator or next to the test method in the editor. In both places it shows up when you hover over it.
You can also use xctool from the commandline with the --only argument, which will only run the specified testcase(s).
As you have noted, the OCUnit test framework marks methods whose name start with 'test' as test cases. This is done at runtime
In practice, your test cases should run so fast that it should not matter how many are enabled; your debugger should be able to stop inside your test case very quickly after you press "Debug".
That being said, the quickest way to disable some tests is probably to use an #if 0 / #endif block. The feature to disable test cases dynamically does not exist in Xcode / OCUnit, since there is no GUI component.
In theory it should be doable, because at runtime (and before all tests are run) there are ways to access the test list in OCUnit, but this requires modifications to the OCUnit source code, which is not desirable (it will be wiped out in the next Xcode update, for one).
Finally, if that feature is important to you, you can easily write your own test harness that mostly replicates what OCUnit does.
Then you can tweak it to your heart's content, add UI, etc.
It is not difficult, and a little educational. Here's a good link to get you started:
http://gusmueller.com/blog/archives/2009/10/how_to_write_your_own_automated_testing_framework.html
Go to View -> Navigators -> Tests (⌘-6)
Find your test case or test and secondary click on it
Run your case/test