junit-nested

JUnit-Nested - Testing tool for Java

Лицензия

Лицензия

Категории

Категории

JUnit Тестирование компонентов Сеть
Группа

Группа

net.avh4.test
Идентификатор

Идентификатор

junit-nested
Последняя версия

Последняя версия

1.0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

junit-nested
JUnit-Nested - Testing tool for Java
Ссылка на сайт

Ссылка на сайт

https://github.com/avh4/junit-nested
Система контроля версий

Система контроля версий

https://github.com/avh4/junit-nested

Скачать junit-nested

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/net.avh4.test/junit-nested/ -->
<dependency>
    <groupId>net.avh4.test</groupId>
    <artifactId>junit-nested</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.avh4.test/junit-nested/
implementation 'net.avh4.test:junit-nested:1.0.1'
// https://jarcasting.com/artifacts/net.avh4.test/junit-nested/
implementation ("net.avh4.test:junit-nested:1.0.1")
'net.avh4.test:junit-nested:jar:1.0.1'
<dependency org="net.avh4.test" name="junit-nested" rev="1.0.1">
  <artifact name="junit-nested" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.avh4.test', module='junit-nested', version='1.0.1')
)
libraryDependencies += "net.avh4.test" % "junit-nested" % "1.0.1"
[net.avh4.test/junit-nested "1.0.1"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.11

test (2)

Идентификатор библиотеки Тип Версия
org.mockito : mockito-core jar 1.9.5
org.hamcrest : hamcrest-integration jar 1.3

Модули Проекта

Данный проект не имеет модулей.

Build Status

Nested tests for JUnit

Add the following dependencies to your pom.xml:

  <dependency>
    <groupId>net.avh4.test</groupId>
    <artifactId>junit-nested</artifactId>
    <version>1.0.1</version>
    <scope>test</scope>
  </dependency>

Now write nested tests as shown below. Your test class can have non-static inner classes, each of which may contain @Test methods. The inner classes themselves can also have inner classes, nested to any depth (though you may want to restructure your tests if you find yourself needing more than two levels). @Before and @After blocks at all levels will be executed as you would expect (for example, Outer-Before, Inner-Before, Test, Inner-After, Outer-After). @Rules at all levels will also be applied in the appropriate order.

import net.avh4.test.junit.Nested;

@RunWith(Nested.class)
public class QueueTest {
    private Queue<String> subject;

    @Before
    public void setUp() {
        subject = new Queue<String>();
    }

    @Test
    public void push_shouldIncreaseCount() {
        subject.push("Item");
        assertThat(subject.count(), is(1));
    }

    public class WhenEmpty {
        @Test(expected = NoSuchElementException.class)
        public void pop_shouldThrow() {
            subject.pop();
        }
    }

    public class WithOneItem {
        @Before
        public void setUp() {
            subject.push("First");
        }

        @Test
        public void pop_shouldReturnTheItem() {
            assertThat(subject.pop(), is("First"));
        }
    }
}

What works

  • @Before methods at all levels
  • @After methods at all levels
  • @Rule fields at all levels
  • @Test(expected) for expected exceptions
  • @Test(timeout) for test timeouts
  • @Ignore for pending tests

What doesn't work (yet)

  • @BeforeClass methods for outer classes
  • @AfterClass methods for outer classes
  • @Rule methods (however, @Rule fields do work) for outer classes
  • @RunWith on inner classes

License

junit-nested is licensed under the Eclipse Public License version 1.0. If you have need of a different license, please contact me.

References

Below are some resources I investigated before writing junit-nested, which offer some different approaches to behavioral testing in Java (and other languages).

Версии библиотеки

Версия
1.0.1
1.0.0
0.0.5