Skip to content

Commit

Permalink
fixing README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yanjustino committed May 1, 2023
1 parent 2f2d7d7 commit 10c9953
Showing 1 changed file with 0 additions and 76 deletions.
76 changes: 0 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,6 @@
<a href='https://www.codacy.com/gh/8T4/gwtdo/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=8T4/gwtdo&amp;utm_campaign=Badge_Grade'><img src="https://app.codacy.com/project/badge/Grade/51e1962835f24f65a3813d078061a9ef"></a>
</p>


# Using the GWTDO Library
Given-When-Then (GWT) is a format for writing executable specifications or automated acceptance tests in Behavior Driven Development (BDD). GWT is a way of structuring test scenarios that makes them easy to read and understand by all stakeholders including developers, QA engineers, and business analysts.
The Given-When-Then structure helps to ensure that the requirements of the system or feature being developed are clearly defined and that everyone involved in the development process has a shared understanding of what is expected.

## What is GWTDO?
Overall, GWTDO defines a BDD-style test suite, with a clear separation of concerns between the test scenario definition and the implementation details.

## How to use GWTDO?
To use a GWTDO library, you need to follow these steps:

1. Add the library to your project: You can either download the library and add it as a reference to your project or use NuGet, a package manager for .NET, to install the library.
2. Import the library: In your code, you need to import the library namespace to access its classes, methods, and properties. You can do this by using the using statement in C#.
3. Use the library: Once you have imported the library, you can use its classes, methods, and properties in your code.

## Example
In this example, we will use the XUnit framework. The domain classes, as well as the code used below, can be accessed [here](src/Samples).

### 1. Specification
This is a BDD-style scenario for a feature named "User trades stocks". The scenario describes the behavior of the system when a user requests to sell a certain number of shares of a particular stock before the close of trading.

```sql
Feature: User trades stocks
Scenario: User requests a sell before close of trading
Given I have 100 shares of MSFT stock
And I have 150 shares of APPL stock
And the time is before close of trading

When I ask to sell 20 shares of MSFT stock

Then I should have 80 shares of MSFT stock
And I should have 150 shares of APPL stock
And a sell order for 20 shares of MSFT stock should have been executed
```

The scenario starts with some preconditions, which are specified using the "Given" keyword. In this case, the preconditions are that the user has 100 shares of MSFT stock and 150 shares of APPL stock, and that the time is before the close of trading. The next step in the scenario is to perform an action using the "When" keyword. In this case, the action is that the user requests to sell 20 shares of MSFT stock.
Finally, the expected outcome of the action is specified using the "Then" keyword. In this case, the expected outcomes are that the user should have 80 shares of MSFT stock and 150 shares of APPL stock, and that a sell order for 20 shares of MSFT stock should have been executed. The scenario provides a clear description of the intended behavior of the system for this specific use case, and can serve as a basis for designing, testing and implementing the necessary features in a BDD-oriented development process.

### 2. BDD-style scenario using GWTDO
This code demonstrates how GWTDO can be used to write BDD-style tests that are readable and understandable by both technical and non-technical stakeholders.

```c#
public class StocksTests : Feature<TradingContext, TradingFixture>, IClassFixture<TradingContext>
{
public StocksTests(ITestOutputHelper output, TradingContext context) : base(context)
{
SetOutputRedirect(new TestOutputRedirect(output));
}

[Fact]
[Scenario(@"User requests a sell before close of trading")]
public void test_with_attribute_mapping()
{
Describe("When an asset is sold",
GIVEN
| "I have 100 shares of MSFT stock" | AND
| "I have 150 shares of APPL stock" | AND
| "The time is before close of trading" |
WHEN
| "I ask to sell 20 shares of MSFT stock" |
THEN
| "I should have 80 shares of MSFT stock" | AND
| "I should have 150 shares of APPL stock" | AND
| "A sell order for 20 shares of MSFT stock should have been executed");
}
}

```
Overall, this code demonstrates how GWTDO can be used to write BDD-style tests that are readable and understandable by both technical and non-technical stakeholders.

The Feature class takes two generic parameters: the [TradingContext](src/Samples/Gwtdo.Sample/TradingContext.cs) and [TradingFixture](src/Samples/Gwtdo.Sample/TradingFixture.cs) classes. In addition, the StocksTests class implements the IClassFixture interface with TradingContext as the generic parameter. This allows the TradingContext to be injected into the test class.

The constructor of StocksTests takes an ITestOutputHelper and a TradingContext object as parameters. It calls the base constructor of Feature with the TradingContext object, and sets up a test output redirect using the ITestOutputHelper object.

The test_with_attribute_mapping() method is a test method with an XUnit attribute [Fact]. The test method uses the Scenario attribute to provide a description of the scenario being tested. The GIVEN, WHEN, and THEN keywords are used to describe the steps of the scenario in a readable format.

# Using the GWTDO Library
Given-When-Then (GWT) is a format for writing executable specifications or automated acceptance tests in Behavior Driven Development (BDD). GWT is a way of structuring test scenarios that makes them easy to read and understand by all stakeholders including developers, QA engineers, and business analysts.
The Given-When-Then structure helps to ensure that the requirements of the system or feature being developed are clearly defined and that everyone involved in the development process has a shared understanding of what is expected.
Expand Down

0 comments on commit 10c9953

Please sign in to comment.