11. előadás: Behaviour driven development

11. előadás: Behaviour driven development

Test Driven Development and Behavior Driven Development

Introduction to Test Driven Development (TDD)

  • The presentation begins with a focus on Test Driven Development (TDD) and Behavior Driven Development (BDD), highlighting their significance in software development.
  • TDD is described as a straightforward process, emphasizing the importance of having existing code to refactor and create tests that will pass.
  • The speaker notes that TDD starts with writing test cases before developing the actual code, which ensures that all tests initially fail due to the absence of code.

The Process of TDD

  • Once tests are written, developers refine their code until these new tests pass, marking the end of the first phase of development.
  • After achieving passing results for new tests, developers run existing tests to ensure overall functionality remains intact before proceeding further.
  • The ideal scenario for TDD is presented; however, it is acknowledged that such perfection rarely exists in real-world applications.

Challenges in Implementing TDD

  • Realistic challenges arise when trying to write comprehensive tests upfront without fully understanding project specifications or requirements.
  • Developers often find themselves needing to adjust their approach during coding due to unforeseen complexities or misunderstandings about functionality.

Integration of Testing and Coding

  • There’s an inherent connection between writing specifications, coding functions, and creating corresponding tests; they should evolve together rather than sequentially.
  • It’s noted that errors can occur during initial design phases which may not be apparent until coding begins. This highlights the iterative nature of software development.

Conclusion on TDD Practices

  • Effective implementation requires collaboration among team members where one writes high-level specifications while another develops software based on those guidelines.
  • A clear distinction is made between writing high-level functional descriptions versus low-level implementation details necessary for testing frameworks like Appium.

Test Driven Development and Behavior Driven Development

Understanding Test Driven Development (TDD)

  • TDD involves thinking about necessary functions, writing tests first, and then implementing the code iteratively. The process is cyclical, where test creation and coding go hand in hand.
  • It’s crucial to recognize that TDD is a reciprocal process; if tests fail, it may indicate issues with either the implementation or the tests themselves.
  • The essence of TDD is to write tests before developing functionality. Once the function works correctly, integration with other components follows.
  • A significant advantage of TDD is avoiding pitfalls associated with premature implementations. Writing tests beforehand helps maintain code quality and clarity.
  • Implementing TDD encourages developers to think architecturally about their code, ensuring it remains testable through proper design practices like using interfaces and dependency injection.

Benefits of Test Driven Development

  • By enforcing a testing mindset from the start, developers can avoid common mistakes such as introducing direct dependencies that compromise code quality.
  • Successful passing of tests indicates functional correctness within the application. This reinforces better coding practices among intermediate and novice developers.
  • While some prefer writing tests after implementation due to practical insights gained during coding, planning for testability in architecture remains essential.
  • Real-world scenarios often reveal specific edge cases during implementation that necessitate additional test cases; thus, flexibility in testing timing can be beneficial.

Transitioning to Behavior Driven Development (BDD)

  • BDD evolves from TDD by extending its principles beyond developers to include decision-makers in the development process.
  • The goal of BDD is to ensure that automated testing aligns with business requirements by communicating effectively with stakeholders using understandable language.
  • BDD aims to bridge gaps between technical specifications and user expectations by emphasizing clear communication regarding what needs to be tested before development begins.
  • Miscommunication often arises from vague descriptions in project documentation; BDD seeks to clarify these details through structured behavior definitions that everyone can understand.

Understanding Behavior-Driven Development (BDD) and Its Tools

The Importance of Clear Test Descriptions

  • Developers often struggle to understand unit test names, which can lead to confusion about what the tests are verifying.
  • Clients want visibility into test cases, but showing them complex code in languages like DNET or Java can be overwhelming.
  • The goal is to express tests in natural language to enhance understanding among different roles, including developers and clients.

Tools and Ecosystems for BDD

  • A presentation will outline available tools in the BDD landscape, emphasizing that while some aspects cannot be fully detached from programming infrastructure, simplification is key.
  • Essential functions for BDD include writing behaviors in a natural language format, primarily English.
  • Two major ecosystems exist: Cucumber and SpecFlow. Cucumber has been widely used but may not receive further development support.

Programming Languages and Framework Integration

  • BDD frameworks like Cucumber allow for behavior descriptions using Gherkin syntax; however, they require programming language support for automation.
  • Tests are written in a way that describes user interactions clearly (e.g., logging out), making it easier to follow the steps involved.

Step Definitions and Integration with Testing Frameworks

  • Each step in a test corresponds to specific actions defined within the framework's programming language (Java or JavaScript).
  • Visual Studio provides robust integration for editing tests, while other environments may have varying levels of support.

Reporting and Documentation Practices

  • Just running tests isn't enough; stakeholders need reports detailing coverage and insights into what tests cover or miss.

Behavior Driven Development (BDD) and Its Applications

Overview of SPR's Business Model

  • The SPR model combines paid and free offerings, with the paid segment ceasing while the community version may continue to evolve without significant new features expected.

Transition from SpecFlow to Light BDD

  • With SpecFlow's stagnation, Light BDD emerges as a more streamlined alternative for new projects in the Dotes ecosystem, maintaining similar principles but with less complexity.

Introduction to Behavior Driven Development (BDD)

  • The presentation focuses on BDD within Java, emphasizing its role in advancing test-driven development by involving all stakeholders in test descriptions.

Importance of Domain-Specific Language in Testing

  • Effective communication between developers and domain experts is crucial; tests should be understandable to both parties, especially in specialized fields like healthcare.
  • For instance, when developing software for complex medical devices, clear specifications are necessary so that developers can accurately implement requirements based on expert input.

Example of Domain-Specific Testing

  • In financial software audits, auditors need assurance that transactions meet specified conditions without delving into code. A behavior-driven test description can provide this clarity.
  • By articulating expectations in layman's terms—like ensuring funds are transferred correctly—auditors can validate functionality without needing technical expertise.

Connecting Human Language with Code

  • The goal is to bridge human-readable domain descriptions with code through step definitions. This connection facilitates understanding across different roles involved in software development.
  • In larger projects, individuals often possess dual expertise—both technical and domain knowledge—which aids in validating requirements during development phases.

Running Tests and Metrics Integration

  • As testing progresses from BDD steps to implementation, less business knowledge is required for execution. Ultimately, all tests must be runnable and yield measurable results.

User Update Feature and BDD Testing

Overview of BDD Test Description

  • The speaker discusses the framework used for Behavior Driven Development (BDD) tests, highlighting a sample test description written in plain text with minimal keywords.
  • A scenario is outlined where user actions are described, such as entering a username and password, clicking the login button, and saving user details.
  • Emphasis is placed on the simplicity of the plain text format used to describe these actions, which aids in understanding the testing process.

Acceptance Tests in Development

  • Acceptance tests are introduced as essential tools that specify what needs to be accomplished during development; they serve as a contract between developers and clients.
  • The importance of having acceptance test lists is discussed; these lists define when development can be considered complete based on specific criteria being met.
  • Clients review and approve acceptance tests before development begins, ensuring alignment on expectations.

Writing Tests Using GKIN Language

  • The GKIN language is presented as a tool for writing BDD tests. It primarily uses plain English or other languages depending on user preference.
  • The speaker notes that while some syntax elements are defined by the language, much of it remains flexible for users to express scenarios freely.

Importance of Precise Requirements

  • Clear documentation of requirements at the start of development is crucial; this includes detailed financial transactions or other specifications that guide coding efforts.
  • Developers are encouraged to think critically about client needs through structured testing processes.

Features and Syntax in GKIN Language

  • An overview of GKIN's syntax reveals key components like features at the top level describing functionalities being tested.
  • Scenarios illustrate different cases under one feature, showcasing how variations in user interactions can be captured effectively within tests.

Step Definitions in Scenarios

  • Key terms such as "given," "when," "then," etc., are highlighted as foundational elements for constructing step sequences within scenarios.
  • Examples demonstrate how these terms help articulate conditions leading up to actions taken by users during testing.

Conclusion: Language Specification Accessibility

Overview of Specification and Gherkin Language

Key Concepts in Gherkin Specifications

  • The specification outlines keywords and provides examples on how to implement docstrings and tags, which are essential for generating documentation from Gherkin tests.
  • Tags are used to attribute different scenarios, allowing for organized execution of various test types such as smoke tests, acceptance tests, daily tests, etc.
  • Features describe the purpose of a test scenario; while descriptions may not be critical, they provide context for understanding the feature's intent.

Structure of Test Steps

  • Each step in a scenario begins with a keyword (e.g., "Given"), indicating what happens at that stage. For example: "Given there is money in my account."
  • The initial conditions are set using "Given," followed by actions taken ("When") and expected outcomes ("Then"), forming a clear narrative structure for the tests.
  • This structure mirrors traditional testing methodologies where preconditions are established before actions are performed and results verified.

Parameterization in Scenarios

  • Scenarios can be parameterized to avoid duplication; this allows for concise representation of multiple cases within a single scenario description.
  • Examples illustrate how parameters work—if starting with 12 cucumbers and eating some, the remaining count can be dynamically calculated based on input values.

Documentation and Usability

  • Gherkin language is user-friendly but powerful enough to facilitate effective communication among team members regarding functional requirements.
  • Online editors enable users without programming environments to write functional tests easily; accessibility is crucial for collaboration across teams.

Real-Life Application of Tests

  • The presentation will transition into practical applications using Java screenshots; however, similar principles apply regardless of programming language or environment.

Understanding BDD and Test Automation

Step Definitions in BDD

  • Step definitions involve creating classes annotated with specific attributes or doc attributes, which help the test framework (like Steckf or KCber) generate unit tests from feature files.
  • The general runner is included in the generated code for a test project, and step definitions are annotated to indicate their corresponding steps.
  • For example, a step like "decount holder requests" can be written using annotations that specify parameters for method calls.
  • Each feature creates an instance of its associated class, where all step calls are executed with appropriate parameter values.
  • It is essential to write code that meaningfully handles these steps and any checks required within the test.

Light BDD Testing Approach

  • A live BDD test closely resembles code but may not achieve the goal of making it accessible for non-programmers, as business stakeholders typically won't write public classes or methods.
  • Steps in this approach mimic BDD but require development effort; there are two setups available that perform similar functions but differ syntactically.
  • Spec flow-based testing is preferred due to its user-friendliness, although it has limitations regarding ongoing development compatibility.

Integration with CI/CD Pipelines

  • The aim is to ensure automated tests can be integrated into Continuous Integration/Continuous Deployment (CI/CD), allowing both unit tests and BDD tests to run seamlessly within pipelines.
  • These tests will function similarly as projects and can influence granularity through tagging mechanisms.

Challenges in Test Automation

  • While automation aims for efficiency without manual intervention, issues may arise post-deployment requiring rollback capabilities if problems occur during production use.
  • Despite thorough automation coverage of workflows, unexpected failures can happen; thus, it's crucial to have strategies for reverting changes when necessary.

Future Discussions on Application Health Monitoring

  • Next week’s discussion will focus on monitoring application health states and systems available for automatic detection of failures during workflows.

Understanding Automation Challenges in Web Testing

Overview of Automation Issues

  • The speaker discusses the importance of ensuring that automation processes do not cause issues when rolling back or returning to previous states after execution.
  • A question is posed regarding students' experiences with automation detection issues during their assignments, encouraging open sharing of challenges faced.

Addressing Automation Detection

  • The speaker admits to not fully testing the assignment before distribution but acknowledges that automation can be detected by web applications.
  • When using Selenium, browsers often identify themselves as automated, which can be visible in network traffic. This identification can lead to restrictions from websites.

Strategies for Bypassing Detection

  • It is possible to override browser identification settings in Selenium, allowing it to mimic a different browser version and hide its automated nature.
  • Websites likely monitor user behavior patterns; rapid input actions may signal non-human interaction, prompting additional security measures.

Realistic User Interaction Simulation

  • To avoid detection, users should simulate realistic typing speeds and behaviors rather than inputting data instantaneously through scripts.
  • There exists a constant tension between user experience and information protection on commercial websites; companies want users while also safeguarding their data.

Balancing Speed and Human-Like Behavior

  • Users might resort to complex setups (like multiple servers or VPN usage) to circumvent restrictions imposed by websites on automated queries.
  • If many users begin automating interactions, websites may implement stricter measures requiring more human-like input methods.

Conclusion and Recommendations

  • The speaker emphasizes the need for careful configuration of HTTP headers in Selenium to ensure successful interactions without triggering security protocols.
Playlists: verval