apim_4xx_support_multiple_analytics_publishers APIM manage workflow with multiple roles APIM 3.0.0 per API based subscription workflow Logging internal HTTP requests Log APIM analytics events to a file Monetization and sample with WSO2 API Manager 2.6.0 Share application and subscription among a set of specific groups or roles WSO2 APIM Correlating analytics event with correlationID APIM analytics distinguish production and sandbox traffic APIM 2.x.x analytics internal and analytics tuneup Configure APIM(Next release) Key Manager User stores APIM(Next release) working with key manager DAS 3.x Parse system variables to Spark Context Revoke OAuth application In APIM 2.1.0 Next WSO2 APIM powered by WSO2 Ballerina Configure WSO2 APIM Analytics on Cluster environment Configure WSO2 DAS 3.1.0 for WSO2 APIM 2.0.0 Analytics WSO2 APIM publishing custom statistics WSO2 APIM Error codes Working with WSO2 message tracer Use DAS admin service to query using Spark SQL Configure WSO2 APIM Analytics using XML WSO2 APIM Generating and Retrieving Custom Statistics Understanding WSO2 APIM Statistics Model Publishing WSO2 APIM 1.10.x Runtime Statistics to DAS with RDBMS Publishing_APIM_1100_Runtime_Statistics_to_DAS Aggregate functions with WSO2 DAS REST API Create a cApp for WSO2 DAS Debugging WSO2 Products using OSGI console. Publishing APIM Runtime Statistics to DAS Deploy cApp on WSO2 DAS How to configure and start the Accumulo minicluster How to setup DNS server on Ubuntu and Ubuntu server How to use Java Reflection how to install apache web server on ubuntu and ubuntu server How to install Mail server on Ubuntu and Ubuntu server How to install squirrelmail webmail client on Ubuntu and Ubuntu Server Pass and return String value to JNI method Pass and return numeric value to JNI method Calling a C Function from the Java Programming Language using JNI AXIS 2 Sample web service Client with maven and eclipse How to setup AXIS 2 with Apache Tomcat AXIS 2 Sample web service with maven and eclipse Robot framework Sample with Selenium Robot framework Custom Library Sample Behaviour-Driven Development with JBehave and Eclipse Play Audio with Netbeans and linking with LibVLC Implement LibVLC based player with QT-part2 Simple Audio playing sample with LibVLC How to install LibVLC on Ubuntu Implement LibVLC based player with QT-part1
Behaviour-Driven Development with JBehave and Eclipse

This Blog is illustrate how to use JBehavior for Behaviour-Driven Development Testing.

1) Introduction

  • What is Behaviour-Driven Development (BDD ):
      • BDD is a software development process and it isinherit from the Test Driven Testing Development (TDD).
  • What is JBehave.
      • JBehave is a Java-based framework supporting Behaviour-Driven Development (BDD).

2) How to Set up Eclipse for JBhave

Lets install the JBehave plugin for JBehave

  1. .open eclipse
  2. .then go to Help>Install New Software
  3. Click the Add button
  4. In the Add Repository dialog, enter:
    • Name: JBehave
    • Location: jBehave – http://jbehave.org/reference/eclipse/updates/
  5. Then select the JBehave option and install the plug in.

how to verify.

  1. go to file->new->other
  2. then select JBehave->New Story
  3. If you can see the "New Story" then installation is succesfull.

3) Create Project.

from file->new create new Java Project Set up Project.

4) Download the Jbehave libraries.

  • commons-collections-3.1.jar
  • commons-lang-2.4.jar
  • freemarker.jar jbehave-core-3.5.4.jar
  • org.apache.commons.io.jar
  • paranamer-2.4.jar
  • plexus-utils-1.0.4.jar

5) Then add the download jar to Eclipse project path.

6) Add Java And BDD test cases.

Create Calculator Project classes.

Here we are going to create simple Calculator BDD test case.

  • create Class Calculator.java in the package com.ruks.core
  • create Class CalculatorStep.java in the package com.ruks.step
  • Then create Story for the JBehavior. From file->new-> other-> JBehave-> new Story.
  • name it as calculator_story.story and in the package com.ruks.story.
  • create Class CalculatorStory.java in the package com.ruks.story

Then lets add the content to the created file.

    • add this to the Calculator.java in the package com.ruks.core
        package com.ruks.core;

        public class Calculator {
            private int sum;

            public Calculator() {
                this.sum = 0;
            }

            public void addTwoNumber(int x, int y) {
                sum = x + y;
            }

            public int getresult() {
                return this.sum;
            }
        }
  
    • add this to the CalculatorStep.java in the package com.ruks.step
        package com.ruks.step;

        import org.jbehave.core.annotations.Given;
        import org.jbehave.core.annotations.Then;
        import org.jbehave.core.annotations.When;
        import junit.framework.Assert;

        import com.ruks.core.Calculator;

        public class CalculatorStep {
            private Calculator myCal;

            @Given("a calculator")
            public void setCal() {
                myCal=new Calculator();
                System.out.println("Created");
            }


            @When("I add $number1 and $number2")
            public void AddCal(int x,int y) {
                myCal.addTwoNumber(x, y);
            }

            @Then("the outcome should $result")
            public void testResult(int output) {
                 Assert.assertEquals(output, myCal.getresult());
            }
        }
  
    • add this to the calculator_story.story in the package com.ruks.story
        Scenario: CAl add testin
        Given a calculator
        When I add 2 and 9
        Then the outcome should 11

  
    • add this to the CalculatorStory.java in the package com.ruks.story
        package com.ruks.story;

        import java.util.List;


        import org.jbehave.core.configuration.Configuration;
        import org.jbehave.core.configuration.MostUsefulConfiguration;
        import org.jbehave.core.io.LoadFromClasspath;
        import org.jbehave.core.junit.JUnitStory;
        import org.jbehave.core.reporters.Format;
        import org.jbehave.core.reporters.StoryReporterBuilder;
        import org.jbehave.core.steps.CandidateSteps;
        import org.jbehave.core.steps.InstanceStepsFactory;

        import com.ruks.step.CalculatorStep;

        public class CalculatorStory extends JUnitStory{
            @Override
            public Configuration configuration() {
                return new MostUsefulConfiguration()
                // where to find the stories
                        .useStoryLoader(new LoadFromClasspath(this.getClass()))
                        // CONSOLE and TXT reporting
                        .useStoryReporterBuilder(
                                new StoryReporterBuilder().withDefaultFormats()
                                        .withFormats(Format.CONSOLE, Format.TXT));
            }

            // Here we specify the steps classes
            @Override
            public List‹CandidateSteps› candidateSteps() {
                // varargs, can have more that one steps classes
                return new InstanceStepsFactory(configuration(), new CalculatorStep())
                        .createCandidateSteps();
            }
        }

  

it seems to be simple calculator BDD project is complete.

7) Let's run the project.

  • Right click on the project and select Run As-> JUnit test.
  • This is how the Test Results looks like.

8) Download the Calculator Project

Add Comment

* Required information
1000
Powered by Commentics

Comments (0)

No comments yet. Be the first!