Jbehave- Basics to Advance

37

Transcript of Jbehave- Basics to Advance

Testing Pyramid

TDD

Acceptance TDD vs Developer TDD

BDD

Why BDD

What’s Changed

QA Myths

You only need to unit test. TDD testing is sufficient.

You can reuse unit tests to build a regression test suite.

We no longer need testers, as Developer have adequate coding skills.

Unit test remove the need of manual testing.

User Acceptance testing is no longer needed.

Automation in so early phases is impossible.

TDD/BDD is applicable on every project.

Developers and testers are like water and oil.

Unit Testing Frameworks in Java

JUnit

Cactus

StrutsTestCase

TestNG

jMock

Grinder

Jetif

Unitils

p-unit

XMLUnit

Ejb3Unit

FEST-Swing

Ripplet

Feed4JUnit

...

Junit vs TestNG

JUnit

@Test Annotation

JUnitCore

Exception Test

@Ignore

Timeout Test

TestSuite

Before and After Annotations

@BeforeClass and @AfterClass

Parameterized Test

TestNG

Annotations

Exception Test

Ignore Test

Timing Test

TestSuite

Parameterized Test

Test Dependency

Group Test and Dependency

Maven

JUnit + Maven

TestNG + Maven

1. Write Story

Create New Maven project using MyNumber class used in previous examples.

Add Jbehave plugin in IntelliJ

Add dependencies of Jbehave and Junit

Add a new story under test resources folder

2. Map Steps to Java

Create a POJO and implement the Given, When, Then Steps

3. Configure Stories

Implement a TestRunner class by extending class JUnitStory.

Override the configuration and stepsFactory methods.

Ensure that story name would be same as test name with _ updated for each Camel Case.

This is because of the configuration used for loading of story, i.e., MostUsefulConfiguration

4. Run the Story

Run the story same as Junit test

5. View Reports

Verify the reports under target/jbehave folder

JUnit-enabled Embeddables

JUnitStory: provides a one-to-one mapping with the textual story.

JUnitStories: provides a many-to-one mapping with the textual story paths

Story Syntax

JBehave Syntax

Narrative:

Lifecycle:

Before:

After

Scenario

Gherkin Syntax

Narrative:

Background:

Given:

Scenario/Scenario Outline:

Gherkin's Background element corresponds to the JBehave Lifecycle Beforeelement.

JBehave also supports a Lifecycle After element which is not currently available in Gherkin.

Prioritizing Steps

For cases in which multiple candidates can match the same textual step, the first candidate that matches is used to create an executable step.

To prioritize one candidate over another simply set a non-zero positive priority.

Story Path’s

Class-path – Arrange in any folder hierarchy within project.

URL-Loader (Running Remote Stories) – Specify the path from a URL

Google-docs (Running Remote Stories) – No more supported, due to change in google authorization, but can be customized, if needed for a project.

Customizing Reports

Specify the FTL File

Define a custom Template that will use the FTL file

Use this reporter in TestRunner

UI Testing

Use Serenity Stories

Specify properties in serenity.properties or from maven command line options

Specify “aggregate” goal to aggregate reports.

REST APIs Testing

Use plugin serenity-rest-assured to invoke rest APIs

CI Setup - Jenkins

Download Jekins from https://jenkins.io/download/

Install Jenkins.