2014-06-18 12 views
5

Mam następujący plik cecha: MacroValidation.featureOgórek: Nie można znaleźć definicję krok

@macroFilter 
Feature: Separating out errors and warnings 
Scenario: No errors or warnings when separating out error list 
    Given I have 0 macros 
    When I filter out errors and warnings for Macros 
    Then I need to have 0 errors 
     And I need to have 0 warnings 

My Files definicji.

package com.test.definition; 

import cucumber.api.java.After; 
import cucumber.api.java.Before; 
import cucumber.api.java.en.Given; 
import cucumber.api.java.en.Then; 
import cucumber.api.java.en.When; 
import cucumber.runtime.java.StepDefAnnotation; 
import java.util.ArrayList; 
import java.util.Arrays; 
import java.util.List; 
import static org.junit.Assert.assertEquals; 
import static org.junit.Assert.assertTrue; 
import static org.powermock.api.mockito.PowerMockito.doReturn; 
import static org.powermock.api.mockito.PowerMockito.mock; 
import static org.powermock.api.mockito.PowerMockito.spy; 


@StepDefAnnotation 
public class MacroValidationStepDefinitions { 

private final MacroService macroService = spy(new MacroService()); 
private final LLRBusList busList = mock(LLRBusList.class);  
private final List<String> errorList = new ArrayList<String>(); 
private final List<String> warningList = new ArrayList<String>(); 

@Before({"@macroFilter"}) 
public void setUp() { 
    errorList.addAll(Arrays.asList("error 1, error2, error 3")); 
    warningList.addAll(Arrays.asList("warning 1, warning 2, warning 3")); 
} 

@After({"@macroFilter"}) 
public void tearDown() { 
    errorList.clear(); 
    warningList.clear(); 
} 

@Given("^I have (\\d+) macros$") 
public void i_have_macros(int input) { 
    doReturn(input).when(busList).size(); 
} 

@When("^I filtered out errors and warnings for Macros$") 
public void i_filtered_out_errors_and_warnings_for_Macros() { 
    macroService.separateErrorsAndWarning(busList, errorList, warningList); 
} 

@Then("^I need to have (\\d+) errors$") 
public void i_need_to_have_errors(int numOfError) { 
    if (numOfError == 0) { 
     assertTrue(errorList.isEmpty()); 
    } else { 
     assertEquals(errorList.size(), numOfError); 
    } 
} 

@Then("^I need to have (\\d+) warnings$") 
public void i_need_to_have_warnings(int numOfWarnings) { 
    if (numOfWarnings == 0) { 
     assertTrue(warningList.isEmpty()); 
    } else { 
     assertEquals(warningList.size(), numOfWarnings); 
    } 
} 
} 

Moja klasa testów jednostkowych.

@CucumberOptions(features = {"classpath:testfiles/MacroValidation.feature"}, 
       glue = {"com.macro.definition"}, 
       dryRun = false, 
       monochrome = true, 
       tags = "@macroFilter" 
       ) 
@RunWith(Cucumber.class) 
public class PageMacroValidationTest { 
} 

Po wykonaniu testu otrzymuję w dzienniku definicję pliku nie zaimplementowane ostrzeżenia.

Przykład dziennika:

You can implement missing steps with the snippets below: 

@Given("^I have (\\d+) macros$") 
public void i_have_macros(int arg1) throws Throwable { 
    // Write code here that turns the phrase above into concrete actions 
    throw new PendingException(); 
} 

@When("^I filter out errors and warnings for Macros$") 
public void i_filter_out_errors_and_warnings_for_Macros() throws Throwable { 
    // Write code here that turns the phrase above into concrete actions 
    throw new PendingException(); 
} 

@Then("^I need to have (\\d+) errors$") 
public void i_need_to_have_errors(int arg1) throws Throwable { 
    // Write code here that turns the phrase above into concrete actions 
    throw new PendingException(); 
} 

@Then("^I need to have (\\d+) warnings$") 
public void i_need_to_have_warnings(int arg1) throws Throwable { 
    // Write code here that turns the phrase above into concrete actions 
    throw new PendingException(); 
} 

Nie sądzę, nazwa pliku powinna znaczenia, prawda?

+0

http://stackoverflow.com/questions/21753267/cucumber-jvm-undefined-step/21754450#21754450 – Bala

Odpowiedz

4

Wygląda na to, że Ogórek nie znajduje Twojej klasy z definicją kroku. W swojej klasie testowej jednostce mówisz:

glue = {"com.macro.definition"} 

Jednak zajęcia definition krokiem są w com.test.definition

Spróbuj zmienić tej linii do:

glue = {"com.test.definition"} 

Być może trzeba będzie odbudować swój projekt, aby podnieść zmiana.

0

Ponadto, Ogórek jest wrażliwy na białą przestrzeń. Jeśli spróbujesz zrobić swój biegacz lub plik funkcji całkiem po przechwyceniu urywków, otrzymasz ten problem.

Oto przykład, który doprowadzał mnie do szału przez kilka godzin podczas tworzenia mojego pierwszego BDD. Stworzyłem plik funkcji i szkielet, który uruchomiłem i przechwyciłem fragmenty. Następnie upiększyłem plik funkcji, a kiedy go uruchomiłem, pojawiły się błędy.

Oczywiście wszystko wyglądało dobrze dla mojego ludzkiego mózgu, więc następne kilka godzin spędziłem na bezowocnych badaniach i sprawdzeniu wersji i list błędów. Ostatecznie zdecydowałem się porównać pierwsze dwa wiersze kodu, aby zobaczyć, co było inne:

// @Then("^the test result is = \"([^\"]*)\"$") 
// public void theTestResultIs(String ruleResult) throws Throwable { 
    @Then("^the test result is   = \"([^\"]*)\"$") 
    public void theTestResultIs(String arg1) throws Throwable { 

Doh!

Powiązane problemy