-1

I have a class with methods like below...

class one{

    @Test
    method1{}

    @Test
    method2{}

    @Test
    method3{}

}

I m using below class to run above Tests using JUnit.

class runsuites{

    @RunWith(Suite.class)

    @SuiteClasses({

        one.class

    }

}

And this runs all the @Test methods.

But, i want to run only methods method1 and method3.

How can I achieve this??

acm
  • 2,086
  • 3
  • 16
  • 34
Bala
  • 184
  • 3
  • 19
  • Side note: just because it is possible to @Ignore certain tests; be careful about really doing that. If some test is "flaky" for example (fails occasionally); then dont ignore it - find the root cause, and fix that. – GhostCat Sep 13 '16 at 14:33

2 Answers2

1

Have a look at this: Grouping JUnit tests

You can use @Category to group tests. First create a category interface.

public interface MyCategory {}

Then add the category to the tests it should be in.

class One {

  @Test
  @Category(MyCategory.class)
  public void method1(){}

  @Test 
  public void method2(){}

  @Test
  @Category(MyCategory.class)
  public void method3(){}

}

And then create a suite for the category:

 @RunWith(Categories.class)
 @IncludeCategory(MyCategory.class)
 @SuiteClasses( { One.class })
 public class RunSuites {}
Community
  • 1
  • 1
Adam
  • 2,214
  • 1
  • 15
  • 26
0

You can annotate method2 with @Ignore annotation. I think a better solution would require some custom library or setting up tests categories (which I recommend):

read about tests categories here

Shadov
  • 5,421
  • 2
  • 19
  • 38