Snicolas
Snicolas

Reputation: 38168

How to exclude a test from a test application using eclipse android-junit launch configuration

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 !

Upvotes: 2

Views: 3671

Answers (4)

Danny Bullis
Danny Bullis

Reputation: 3199

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.

Upvotes: 2

Di Wang
Di Wang

Reputation: 104

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.

Upvotes: 0

yorkw
yorkw

Reputation: 41126

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

Upvotes: 5

Jin35
Jin35

Reputation: 8612

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

Upvotes: 1

Related Questions