# Тест сьюты

Тест сьют - это связка тест кейсов в один набор. Эта фича реализована и в JUnit 4 и в TestNG, но сделано это по-разному.

**JUnit 4**

“@RunWith” и “@Suite” аннотации используются для запуска тест сьюта. Класс, написанный ниже, означает, что классы “JunitTest1” и “JunitTest2” будут запущены после запуска JunitTest5. Все остальные декларации будут внутри класса.

```
@RunWith(Suite.class)
@Suite.SuiteClasses({
        JunitTest1.class,
        JunitTest2.class
})
public class JunitTest5 {
}
```

**TestNG**

XML файл используется для запуска тест сьюта. Файл, приведенный ниже, означает, что классы “TestNGTest1” и “TestNGTest2” будут запущены вместе.

```
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="My test suite">
  <test name="testing">
    <classes>
       <class name="com.fsecure.demo.testng.TestNGTest1" />
       <class name="com.fsecure.demo.testng.TestNGTest2" />
    </classes>
  </test>
</suite>
```

TestNG может не только группировать тесты по классам, но и по методам (тестам). С помощью аннотации "groups" любой тест может быть занесен в одну или более группы. А затем можно будет запустить ту или иную группу тестов (одну или несколько). Таким образом, можно, например, группировать тесты по фичам.

Вот пример класса с 4 методами и 3 группами(method1, method2 and method3)

```
    @Test(groups="method1")
    public void testingMethod1() {  
        System.out.println("Method - testingMethod1()");
    }  

    @Test(groups="method2")
    public void testingMethod2() {  
        System.out.println("Method - testingMethod2()");
    }  

    @Test(groups="method1")
    public void testingMethod1_1() {  
        System.out.println("Method - testingMethod1_1()");
    }  

    @Test(groups="method4")
    public void testingMethod4() {  
        System.out.println("Method - testingMethod4()");
    }
```

Используя следующий файл конфигурации, мы можем запустить только тесты из группы “method1”.

```
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="My test suite">
  <test name="testing">
      <groups>
      <run>
        <include name="method1"/>
      </run>
    </groups>
    <classes>
       <class name="com.fsecure.demo.testng.TestNGTest5_2_0" />
    </classes>
  </test>
</suite>
```

К концепцией групп возможности для интеграционного тестирования безграничны. К примеру, можно запускать тесты, относящиеся к базе данных, добавив их в группу “DatabaseFuntion” (название случайное).

Задание 1. Напишите тест, принадлежащий одновременно нескольким группам.

Задание 2. Напишите файл конфигурации для запуска нескольких групп,


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://comaqa.gitbook.io/java-automation/yunit-testirovanie/junit-vs-testng.-primery-testov/test-syuty.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
