Behat (software)

From Wikipedia, the free encyclopedia
(Redirected from Behat (computer science))
Jump to navigation Jump to search
Behat
DeveloperKonstantin Kudryashov
Initial release8 September 2010; 15 years ago (2010-09-08)[1]
Stable release
3.27.0 / 23 November 2025; 4 months ago (2025-11-23)[1]
Repository
  • {{URL|example.com|optional display text}}Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
Written inPHP
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemCross-platform
    TypeBehavior-driven development
    LicenseMIT License
    Websitebehat.org

    Behat is a test framework for behavior-driven development written in the PHP programming language. Behat was created by Konstantin Kudryashov and its development is hosted on GitHub.

    Purpose

    [edit | edit source]

    Behat is intended to aid communication between developers, clients and other stakeholders during a software development process. It allows the clear documentation of testable examples of the software's intended behaviour. Behat test scenarios are written with Gherkin,[2] a business-readable domain-specific language following defined patterns.

    Benefits

    [edit | edit source]

    Tests can be run at any point new code is introduced into a codebase to confirm no regressions within the existing test coverage are introduced. It can be used to directly test php code and is often used with Selenium to remote control browsers as part of the scenarios. The browsers under remote control can take videos[3] or screenshots of failures. Using selenium or tools like selenoid[4] a "grid" of browsers can be remote controlled for parallel test execution. There is also a module for running php only scenarios.[5]

    Like other BDD frameworks, Behat scenarios are a series of Given, When, and Then steps that explain a business case. The definition of these steps exist within method annotations of a class that extends the BehatContext.[6]

    Behat can output test results in a number of different formats, including JUnit XML and HTML[7]

    Examples

    [edit | edit source]

    The preconditions after "Given" correspond to the PHP method name to execute:

    Feature: Simple description of this feature’s story
    
      Describe benefit, role and feature or user story
      Use as many lines as needed
    
      Background:
        Given some step run for all scenarios
        
      Scenario: Scenario or example description
        Given I setup preconditions with:
          | data column 1 | data column 2 |
          | alice         | bob           |
        When I press the "blue" button
        Then the result is:
        """
        A multiple line
        string of data
        """
    
        #comments can be added as needed
    
      Scenario Outline: Scenario or example description using setting <setting>
        Given I setup config with "<setting>"
        When I push button "<button>"
        Then "<result>" happens
        Examples:
          | setting | button | result           |
          | a       | red    | there is a beep  |
          | b       | blue   | there is no beep |
    

    References

    [edit | edit source]
    1. ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    6. ^ BDD With Behat - Tuts+ Code Tutorial. Code.tutsplus.com (2013-12-23). Retrieved on 2015-03-19.
    7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    [edit | edit source]
    • Lua error in Module:Official_website at line 94: attempt to index field 'wikibase' (a nil value).

    Lua error in mw.title.lua at line 392: bad argument #2 to 'title.new' (unrecognized namespace name 'Portal').