How to run specific tests from one class xcode uitesting - swift

I'm creating ui tests in xcode using XCTest(Swift)
How can I run, for example, 2-3 tests from one class without launching the rest of the test from this class?
Is it possible to add some tests to suite or run and run from command line just necessary suite/run?
According to the XCTestSuite documentation there is an option to create a custom test suite, but I haven't found any examples of it.

You can adjust which tests you want to run in the scheme, under the Test menu. There will be a list of your test classes and tests in a disclosure triangle hierarchy in the Edit Scheme > Test window, where you can select or deselect tests. When you run the tests with that scheme selected, only the tests you selected will run.

You can use multiple -test-only params in your run
xcodebuild test [...] -only-testing:"superApp/SuperTestClass/test2" -only-testing:"superApp/SuperTestClass/test5"

Related

Is there a way to run tests without doing a full build in Xcode?

Is there a way to provide a small test window without performing a complete build in Xcode? I know that eclipse gives you a small preview window at the bottom of the IDE but I can not figure it out for Xcode. I am mainly looking to test certain conditions and outputs that may not always print a value to the screen. Any suggestions?
Move your testable code into a framework that is accompanied by its own unit test bundle. Now testing involves just clicking the little run button next to a unit test. You can run a single test method or a whole suite, depending on your needs. When you run a test, the entire app does not need to be built — just the framework; and the app itself never runs and the Simulator never opens. And the results appear in the little Xcode Console pane at the bottom of the project window (and are preserved also in the Report navigator).
This is an excellent way to organize your app structure. I routinely use this kind of architecture.

Eclipse run test one by one

I'm looking for a way to run a only a one test case in my test class from the some kind of test methods list.
For example, when I run a whole batch of test methods, the failure list appears like that:
And I can right-click on the appropriate test method and re-run it without a running a whole batch. But in the next i'm getting the error list, that consists of only that method:
At that point it would be nice to run the another test method as only one, without running a whole batch. Is there a way in Eclipse to get the list of my test methods where it's would be possible to choose the method to run?
In the JUnit view toolbar there is a Test Run History... button/drop-down where you can go back to the test result of a previous run without rerunning it.
In addition, you can also right-click on a test method to run this method only: for example in the Java editor, in Outline view of the Java editor, in the Package Explorer or in the Project Explorer.

PerlUnit in Eclipse

If we click on Java perspective in Eclipse and right click on a Java project, we see “new” a JUnit file.On executing the test cases in JUnit we see red/green bar displaying failure/success of test cases.
I am trying to find a plugin that would add these two features :
In the perl perspective (provided by EPIC) , right-click on a Perl
project should list a new “t” file.
On executing perl unit the status of test cases should be displayed
using Reed/Green bar.
If there is no plugin is there a way we can do the same.
As far as I know, there is no EPIC plugin for this or even a more generic TAP-based test runner for Eclipse. Such a thing would be nice to have.
Rigging some sort of report on test success from a web page is pretty common. This can be done using a tool like Test::Harness which can be used to run your test or tests and return or output a report of how well your test run went.
From there, it's a matter of turning that into a red/green progress bar.
If you want to see the progress updated continuously during the test run, you'll have to run and parse the test files more directly as they run. All Perl tests output TAP format, which is a standard format with specs available here:
http://testanything.org

Why my XCode unit test does not work at all?

I created a empty test project (static library type) with enabling the unit test.
But after that the product of the unit test is red as shown on the picture below.
Also I can't find a schema for the test and I can't even run the test.
Any one can help me out?
Press and hold the run button and select test. Or go Product>Test from the toolbar. It will then build your target you want to test and run the tests on that.

Running a single JUnit test in Eclipse

If I have a test suite with multiple tests, when I try to run a single unit test, either from the context menu of the code editor, or from the JUnit view, it seems to insist on always running the entire suite, rather than the single test. Is there a way to disable to change this behavior so that I can ask to to run that, and only that, test.
In the package explorer unfold the class. It should show you all methods. Right click on the one method you want to run, then select Run As -> JUnit from the context menu (just tested with Eclipse 3.4.1). Also selecting "Run" on a single entry in the JUnit-results view to re-run a test works in the same way.
Fastest way I know of:
Press Ctrl+Shift+↑ (moves cursor to current method declaration),
press Alt+Shift+x (or d for debug) then press t (hotkey for "Run JUnit Test"),
check test result,
press Alt+← to get back to the line of code you were before.
If you want to run all tests, you can skip steps 1 & 4.
In Eclipse 3.5, you can get around this by changing the test runner to JUnit 3. This will only work for JUnit 3 tests, not JUnit 4 tests. You can change the test runner by doing the following:
Right click on one of the test methods in the Outline explorer
Select Run As -> Run Configurations
On the 'Test' tab, select 'Run a single test'
In the Test Runner dropdown, select 'JUnit 3'
It may work in other versions as well.
This is possible in Eclipse Indigo with JUnit 4.8.2. You right click the method you want to unit test individually in the Outline pane, and select Run As -> JUnit Test.
You can even selectively right click a Test method name in the source editor and select Run As -> Junit Test.
Don't use Strg+F11 but the hotkey Alt+Shift+X -> T.
Then Eclipse will execute the current open file as a JUnit test. The green play button will only run the last chosen Run Configuration.
For me, it works well with Alt+Shift+X -> T.
I'll add to the others by including a highly productive keyboard only way that allows you to debug a single unit test (method).
Move your cursor to the method name by using either
Ctrl+Shift+Up or
Ctrl+Shift+Down or
Ctrl+o then type the name of the method
Once your cursor is on the method name (or right before it):
Alt+Shift+D -> T (Debug)
Alt+Shift+X -> T (Run)
After you run the test you can go back to where your cursor was by doing:
Alt+Back
You almost get REPL like behavior by:
Ctrl+Shift+Up and Alt+Shift+X -> T and Alt+Back
You can also quickly set a breakpoint:
Ctrl+Shift+B
Right click somewhere on the test method name in the file and select "Run" -> "Junit Test". I do it all the time with Kepler and JUnit 4.
To run only one test method.
In the (package explorer or project explorer) unfold the class. It should show you all methods. Right click on the one method you want to run, then select Run As -> JUnit from the context menu.
I had the same problem others have had using Eclipse 3.4.1 and JUnit 4 test runner -- couldn't run single test. But I found a suggestion somewhere else that resolved the problem. My test class was still extending junit.framework.TestCase. When I stopped extending TestCase, everything worked fine and I was able to run single JUnit tests with the JUnit 4 test runner. Of course, I needed to JUnit 4 annotations use static imports for the assert methods, but I had already done that -- I had just not removed the TestCase inheritance.
If you have many tests in more than one file, and you want to run only the tests in a particular file, you could right click that file, and select run as -> junit test.
Now, if you want to run only one test, contained in a file with many tests, my guess is (I dont have eclipse installed here) that the Outline view will list all test methods for a file, and you will probably be able to right click a single test method and execute it as a JUNit test.
Hope it helps.
For me, it also does not work in Eclipse 3.4.2 , although it worked in the previous releases (I have tried running single method from package explorer and single junit test from junit view)
I agree with the point about 3.4.2 no longer working the way it did in previous versions. Before you could right-click on a single test in a group of tests from the JUnit view and execute just that test. In the latest version it insists on always running all of them. Granted, the view does run the test you clicked on first and dumps the rest in a rollup called "Unrooted Tests". If anyone figures this out I'd like to know how to get around it.
Reading some of the comments here, it seems you might be interested in running the tests for the code you change as you change it, without losing focus on the code you are working on. There's an eclipse plugin for doing just that. See infinitest.
If by test you might even mean single test method I like to use "Run Tests of Selected Member" using a key binding.
When I am inside of a test method only that test method will be run – if I have the cursor in the class scope it will run the whole class. I changed the default binding to something easy like Ctrl+r since I use it a lot.
Please see:
(If you don't see that keys entry it might come from the MoreUnit plugin – which is great anyway and you might want to have it)