среда, 1 августа 2012 г.

testing: junit - categories

import org.junit.Test;
import org.junit.experimental.categories.Categories;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

interface Slow {/*category marker*/}

interface LotOfMemory {/*category marker*/}

class ClassWithTestsA {
    @Category({})
    @Test
    public void test0() {
        System.out.println("test0");
    }

    @Category({Slow.class})
    @Test
    public void test1() {
        System.out.println("test1-Slow");
    }

    @Category({LotOfMemory.class})
    @Test
    public void test2() {
        System.out.println("test1-LotOfMemory");
    }
}

class ClassWithTestsB {
    @Category({Slow.class, LotOfMemory.class})
    @Test
    public void test3() {
        System.out.println("test1-Slow-LotOfMemory");
    }
}

@RunWith(Categories.class)
@Categories.IncludeCategory(Slow.class)
@Suite.SuiteClasses( { ClassWithTestsA.class, ClassWithTestsB.class })
class SlowTestSuite {}

@RunWith(Categories.class)
@Categories.IncludeCategory(LotOfMemory.class)
@Suite.SuiteClasses( { ClassWithTestsA.class, ClassWithTestsB.class })
class LotOfMemoryTestSuite {}