Я только начал использовать JBehave для BDD, и у меня есть одна большая проблема. Каждый раз, когда утверждение не выполняется, исключается исключение в моей среде Netbeans, а остальные тесты не выполняются. Но я хочу, чтобы этот тест был отмечен как неудачный и выполнил другие тесты. Я много искал, но не было решения моей проблемы.JBehave: Не бросайте исключение Assert
История:
Narrative:
In order to manage our stock efficiently
As a logistic employee
I would like to handle returns and changes in a proper way
Scenario: Return of a phone
Given there is an empty stock
And there are 2 A phone(s) in stock
When a customer returns the not damaged A phone
Then there should be 2 A phone(s) in stock
Scenario: Exchange of a phone
Given there is an empty stock
And there are 5 A phone(s) in stock
And there are 5 B phone(s) in stock
When a customer changes his A phone for a B phone
Then there should be 6 A phone(s) in stock
And there should be 4 B phone(s) in stock
ScenarioLoader
public class LogisticScenarios extends JUnitStory {
@Override
public Configuration configuration() {
URL storyURL = null;
try {
// This requires you to start Maven from the project directory
storyURL = new URL("file://" + System.getProperty("user.dir")
+ "/src/main/resources/stories/");
} catch (MalformedURLException e) {
e.printStackTrace();
}
return new MostUsefulConfiguration()
.usePendingStepStrategy(new FailingUponPendingStep())
.useStoryLoader(
new LoadFromRelativeFile(storyURL)).useStoryReporterBuilder(
new StoryReporterBuilder().withFormats(Format.HTML));
}
@Override
public List<CandidateSteps> candidateSteps() {
return new InstanceStepsFactory(configuration(), new LogisticSteps())
.createCandidateSteps();
}
@Override
@Test
public void run() {
try {
super.run();
} catch (Throwable e) {
e.printStackTrace();
}
}
}
Шаги
public class LogisticSteps extends Embedder {
List<Phone> stock;
@Given("there is an empty stock")
public void initializeStock() {
stock = new LinkedList();
}
@Given("there are $quantity $type phone(s) in stock")
public void fillStock(String quantity, String type) {
stock = stock == null ? new LinkedList() : stock;
PhoneType pType = type.equals("A") ? PhoneType.A : PhoneType.B;
addPhonesToStock(pType, Integer.parseInt(quantity));
}
@When("a customer returns the not damaged $type phone")
public void customerReturnsPhone(String type) {
PhoneType ptype = type.equals("A") ? PhoneType.A : PhoneType.B;
addPhonesToStock(ptype, 1);
}
@When("a customer changes his $type1 phone for a $type2 phone")
public void customerExchangesPhone(String type1, String type2) {
PhoneType pType1 = type1.equals("A") ? PhoneType.A : PhoneType.B;
PhoneType pType2 = type2.equals("A") ? PhoneType.A : PhoneType.B;
stock.add(new Phone(pType1));
removePhoneFromStock(pType2);
}
@Then("there should be $quantity $type phone(s) in stock")
public void thePositionReturnedShouldBe(String quantity, String type) {
PhoneType pType = type.equals("A") ? PhoneType.A : PhoneType.B;
Assert.assertEquals(Integer.parseInt(quantity), countPhonesFromType(pType));
}
private void removePhoneFromStock(PhoneType type) {
for (int i = 0; i < stock.size() - 1; i++) {
if (stock.get(i).getType() == type) {
stock.remove(i);
break;
}
}
}
private int countPhonesFromType(PhoneType type) {
int count = 0;
for (Phone p : stock) {
if (p.getType() == type) {
count++;
}
}
return count;
}
private void addPhonesToStock(PhoneType type, int quantity) {
for (int i = 0; i < quantity; i++) {
stock.add(new Phone(type));
}
}
}
Спасибо за вашу помощь