Is it possible to create a list of tests to run in IntelliJ IDEA? - intellij-idea

In Visual Studio each test and class with tests has an icon next to it that opens a dropdown to either run the tests, debug the tests or add them to a new test session. IntelliJ IDEA only has the options to run the tests or debug the tests.
Is there any way to create a list of tests from potentially disparate parts of the test suite then run them all in one go?
I'm using Junit 4 and if there's a plugin to do this, that would be satisfactory.

You can right click on a package (and/or a selection of packages) and then choose Run or Debug from the context menu.
Here's a screenshot showing that in action:
The resulting Run Configuration is then available via Run > Edit Configurations where you can edit/add/remove packages/classes from the selected pattern ...
You could also create a JUnit suite or category and let it contain your 'tests of interest' and then run it via IntelliJ's JUnit runner.

Related

Run cucumber by right clicking on it in IntelliJ

I am trying to simplify the way we run cucumbers. We have a runner for each folder and we always change the runner in a run configuration that has some VM options set.
I can right click on a feature, select "Run feature :" but it doesn't run successfully without the parameters from the run configuration (one of them runs the tests with an in memory database for example)
Is there anyway I can add a default configuration so I can run them directly?
Run -> Edit Configurations
In the left-hand panel, there is a category called defaults. You can set the defaults to cucumber there. However, note that you might have to delete your previously existing configurations to get this to work with files you've already tried. They usually appear in a faded gray.
In addition, you could also add a runner class, which can run (a subset of) your tests from a testing framework. You can provide #CucumberOptions in this runner.

Is there a way to run a JUnit test for a particular class in IntelliJ without compiling the entire project?

I have a project in IntelliJ that has a number of syntactically correct and incorrect classes and a unit test that I've written for a particular class.
Is there a way to execute the test even though other classes, completely independent from the current class I want to test, have errors that prevent the entire project from compiling?
The class I want to test has no compile-time errors. When I try to run the test, I'm directed to those other classes with syntax errors.
Replace the Before launch Build step with Build, no error check:
Do this change for the default JUnit configuration (under Defaults node in the tree on the left) so that it's applied to all the new JUnit run/debug configurations automatically.
You can also remove the Build step and compile the test files manually (from the file right click context menu):

IntelliJ 14 Gradle task in Test Runner

Upgraded to IntelliJ 14.0.1 One of the big new features I was looking for:
"If you run tests via a Gradle task, the IDE offers you the standard Test Runner instead of the console output." (Source: https://www.jetbrains.com/idea/whatsnew/#buildTools)
I right click on the Gradle Task to run our Integration Tests:
However, I see the results of the test still going to console output, not to the Test Runner:
Has anyone been able to get this new feature in IntelliJ IDEA 14 to work?
Thank you in advance,
Philip
Looks like IntelliJ looks for a task named "test" rather than a task of type Test.
https://github.com/JetBrains/intellij-community/blob/master/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleTestsExecutionConsoleManager.java#L191
Rename the test task to unitTest and then create a wrapper that runs both:
// Rename test to unitTest
tasks.test.name = "unitTest"
// Wrap and run both
task test(dependsOn:['unitTest', 'integrationTest'])
If you only want to run integration tests, just overwrite it:
task test(overwrite: true, dependsOn: ['integrationTest'])
This allows me to run the integration tests in the test runner successfully (at least it works in IDEA 15 EAP but it should work in 14 as well I would think).
I still get this in IntelliJ 2017.1, but specifically when running tests in the gradle buildSrc directory. After digging a while, it turns out that the Gradle API doesn’t expose the test tasks in the special buildSrc directory to Intellij, so IntelliJ doesn’t recognize it as a test.
Workaround: Open another IntellIJ project for the buildSrc directory directory instead of trying to run tests cleanly inside the root project.

Running TestNG Test in IntelliJ

After running Rebuild Project successfully in IntelliJ 13.1.3 Ultimate IDE, I opened my Test NG test file.
When right-clicking on the file, I don't see any option to run the test.
How can I run an TestNG test in IntelliJ 13.1.3?
This question is similar, but it's from 2012 with an unaccepted answer.
Yes you can!
Сheck the folder that contains the test classes whether marked as Test Source Root. In another case see whether installed TestNG-J plugin.
Update:
There are 3 possibilities in the new Intellij 2017.2 to run a testNG test.
You can click on the module (project) name >>Run>>All Tests(TNG). Be careful as there are 2 'All Tests' options. The second option is the one you need. It carries a testNG logo. This way you can run all your testNG classes in parallel
The second possibility is to run a single TestNG class. Righ click the class name in the package explorer and choose 'Run Test' If your class is a testNG class, by default, the test will run as a TestNG test.
This option is my favourite as it gives me a lot of control over my tests. Install this 'Create TestNG XML' plugin. Once installed. if you right click on your module name, you will see a new option called 'Create TESTNG XML' and you will be able to directly use that option to run your TestNG tests, giving you a lot of flexibility.
It could be that a plugin that you need is disabled.
Make sure the testNg plugin is enabled.
I noticed this plugin wasn't enabled,
and as soon as I turned it on, everything started working.

"Test After Build" option in XCode 4 not working

So, I am having a bear of a time figuring this one out. I have looked around, and cannot seem to find any information on this.
What I want to do is have my unit tests ALWAYS run EVERY time I build my code in XCode. I have read a number of posts, including this question here. I have followed the instructions to the letter, and the build will not run the tests.
What I have done:
My Test suite is a target dependency of my main build
My main build has "Test After Build" set to Yes
All of the tests under the "test" phase in the Scheme are there, and checked
If I run the tests manually - through cmd+U or the menu - the tests run. I have added a failing test to try and force the build to fail - so I can be sure they are running. The build continues to pass fine, and the tests are never run.
I am positive I have missed a step in here, but for the life of me I cannot find any documentation related to it. Anyone have any other advice or steps I should be doing?
It doesn't matter whether or not "Test After Build" is set to yes or no in your Something.app target. It is only necessary to set "Test After Build" to YES in the unit test target. Also make sure that both "Test" and "Run" are selected for your unit test target in the scheme editor under the "Build" tab options. To see the results click on the Log Navigator View > Navigators > Show Log Navigator (command 7).
In your main target's Build Phases, add a new Run Script build phase. The content of the script should be:
"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests"
That will run the tests - but only if it can find the .octest files generated by your project. RunUnitTests wants PRODUCT_NAME to be the name of your unit test, and WRAPPER_EXTENSION to be .octest (these are Xcode variables). If your main target is an aggregate target that has your tests AND your app as dependancies, you can probably make it work with that in mind.