2

I got an application project under test and a test application project (on Android).

My test app contains a lot of tests but I would like to find a mechanism to exclude a test, or a test class from the test launch (launched from eclipse).

I know I can exclude tests on the command line based on annotations for instance, or use ant to exclude classes, but I don't have this kind of configuration and want to exclude them directly from eclipse).

Is it possible to exclude a test, or a bunch of tests from a from a test application using eclipse android-junit launch configuration ?

Thanks in advance !

Snicolas
  • 37,840
  • 15
  • 114
  • 173

4 Answers4

5

Android JUnit Test launch configuration is lack of functionality which only support configure running either all tests or single one test class at the moment.

Alternatively, instead of trying to include/exclude tests right before junit run time, we can include/exclude specific test source files at project build time by configuring project build path in Eclipse, right-click your test project, go to Build Path -- Configure Build Path, in the Source tab, edit Excluded section and add multiple test source files, this will exclude the test source files from your project build path and finally exclude them when you start running Android JUnit test: enter image description here

yorkw
  • 40,926
  • 10
  • 117
  • 130
  • +10 for the suggestion but it s not what I am looking for. Thx for answering – Snicolas Feb 22 '12 at 09:51
  • If it's no longer part of the source path it will be missed by refactorings and may break the build done by your build tool. So I think it's not so nice. – Volker Seibt Sep 15 '21 at 15:38
2

DISCLAIMER: This answer is for normal JUnit 5 Test configurations, and is not Android specific. But since this was the first result I got for a more generic Google search, I figured I'd update here for whom it may benefit.

As of Eclipse Oxygen (4.7.3a), I am able to create a new JUnit Run Configuration and add Tags to include/exclude during a test run. Classes (and I believe methods too) can be decorated with the @Tag("") annotation and the test runner will filter those out. I am using JUnit 5 with a relatively straight-forward Java application using the Spring Framework.

Run > Run Configurations... > JUnit > New > Configure...

enter image description here

I have a package src/test/java, with a test class called JoinConfigIT, with an annotation at the top of my classed of @Tag("integration").

enter image description here

Now when I run the IntegrationTests run configuration that I created, it only runs all tests with classes decorated with the @Tag("integration") annotation.

I hope this helps someone. Good luck.

Danny Bullis
  • 3,043
  • 2
  • 29
  • 35
1

You can use annotations @SmallTest, @MediumTest or @LargeTest and create different configurations for launching different tests. See this docs.

Jin35
  • 8,602
  • 3
  • 32
  • 52
  • What do you mean "in eclipse"? All this can be done with eclipse. – Jin35 Feb 20 '12 at 14:21
  • But how do you express the filter by annotation in eclipse ? There is no option in the launch test wizard – Snicolas Feb 20 '12 at 14:31
  • try this: right click on test project -> `properties` -> `run/debug settings` -> `new` -> `android junit` -> `target` tab -> `additional options` at bottom -> write `-e size small` – Jin35 Feb 20 '12 at 15:28
  • Sorry but this doesn't work, it's just a boxe for the emulator options, not for instrumentation options ! – Snicolas Feb 21 '12 at 07:56
0

I think testSuite class would do the trick. It is designed to help organize tests.

Please reference sample code in apiDemos test and read corresponding doc. Best of luck.

Di Wang
  • 104
  • 6
  • Sorry but I am looking for a way to exclude tests based on annotation automatiaclly. This solution would work, as others, but is not automatic neither. – Snicolas Feb 27 '12 at 06:45