Tworzenie testów akceptacyjnych Instrukcja dla

Transkrypt

Tworzenie testów akceptacyjnych Instrukcja dla
Tworzenie testów akceptacyjnych
Instrukcja dla środowiska IntelliJ
1. W celach prowadzenia testów potrzebny będzie zainstalowany plugin „Cucumber for Java” (jeżeli nie jest
zainstalowany to pobrać z repozytorium).
2. W katalogu testów należy utworzyć plik z rozszerzeniem .feature oraz nazwą wskazującą co będzie
testowane, np jiraIntegration.feature;
3. W pliku feature należy utworzyć opis testu testowanej funkcjonalności, np:
Feature: Get list of all projects from Jira and then get details of one of
them
As a handlowiec
I want to get project from Jira
So I can see its details
Scenario: User gets list of projects from Jira
When User chooses the action to get all projects
Then Service should return list of projects
Scenario: User gets details of project
Given There is a project in Jira of which details user intends to get
When User chooses the action to get details of project
Then Service should return details of project
Opis należy napisać w języku gherkin: http://docs.behat.org/en/v2.5/guides/1.gherkin.html
4. Po napisaniu scenariuszy należy utworzyć definicje kolejnych kroków (ang. Step definitions dla opisanych
testów (alt + enter -> Create step definition -> wybieramy/tworzymy plik, w którym mają się znaleźć testy;
wybieramy file type „Java”, z Java 8 są jakieś problemy -> ok). Należy pamiętać, żeby kroki znalazły się w
jednym pliku.
5. Po utworzeniu wszystkich kroków w ciele klasy testującej znajdować się będzie coś takiego:
@When("^User chooses the action to get all projects$")
public void userChoosesTheActionToGetAllProjects() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^Service should return list of projects$")
public void serviceShouldReturnListOfProjects() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Given("^There is a project in Jira of which details user intends to get$")
public void thereIsAProjectInJiraOfWhichDetailsUserIntendsToGet() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^User chooses the action to get details of project$")
public void userChoosesTheActionToGetDetailsOfProject() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^Service should return details of project$")
public void serviceShouldReturnDetailsOfProject() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
6. Jak podpowiadają komentarze, w poszczególnych krokach należy wpisać wywołania metod/assercje
realizujące to, co jest w opisie:
@Autowired
private JiraController jiraController = new JiraControllerImpl();
private List<JiraProject> jiraProjects;
private JiraProjectDetails jiraProjectDetails;
@When("^User chooses the action to get all projects$")
public void userChoosesTheActionToGetAllProjects() throws Throwable {
jiraProjects = jiraController.getAllJiraProjects();
}
@Then("^Service should return list of projects$")
public void serviceShouldReturnListOfProjects() throws Throwable {
assertNotNull(jiraProjects);
}
@Given("^There is a project in Jira of which details user intends to get$")
public void thereIsAProjectInJiraOfWhichDetailsUserIntendsToGet() throws Throwable {
jiraProjects = jiraController.getAllJiraProjects();
assertNotNull(jiraProjects.get(0));
}
@When("^User chooses the action to get details of project$")
public void userChoosesTheActionToGetDetailsOfProject() throws Throwable {
jiraProjectDetails = jiraController.getProjectDetails(jiraProjects.get(0).getId());
}
@Then("^Service should return details of project$")
public void serviceShouldReturnDetailsOfProject() throws Throwable {
assertNotNull(jiraProjectDetails);
}
7. Aby wszystko zadziałało w pliku pom.xml znajdować powinny się następujące zależności:
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-spring</artifactId>
<version>1.0.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.0.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.11</version>
<scope>test</scope>
</dependency>
Dodatkowo klasa testowa powinna posiadać adnotacje @RunWith(Cucumber.class). Należy także utworzyć plik
cucumber.xml (opis beana) w katalogu „resources” kontekstu, w którym będą wywoływane testy
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="pl.wroc.pwr.ie"/>
<context:annotation-config/>
</beans>
8. Po tych zabiegach odpalamy plik .feature co spowoduje zbudowanie projektu i uruchomienie testów