Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# These are supported funding model platforms

github: [yanjustino]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
thanks_dev: # Replace with a single thanks.dev username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
73 changes: 22 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,44 +97,41 @@ TEST RESULT: 🟢 SUCCESS
| THEN ↘ she sees a Free article and a Paid article
```

### ✏️ Customizing the lexical elements of Gherkin
### 🔎 Is GherXunit for You?
If your team already uses xUnit and wants to experiment with a BDD approach without drastically changing its workflow, **GherXunit** may be an option to consider. It does not eliminate all BDD challenges but seeks to facilitate its adoption in environments where xUnit is already widely used.
See more usage examples and implementation details for `Background`, `Rule`, `Features`, and other elements in the [sample code](/src/base/GherXunit.Core/Samples) available in the **GherXunit** repository.

The **GherXunit** allows you to customize the lexical elements of Gherkin, such as `Given`, `When`, `Then`, `And`, `Background`, `Scenario`, and `Feature`.
You can define your custom emojis or symbols to represent these elements. The following code snippet shows an example of a custom lexer for emojis:
```csharp
// Custom lexer for emojis
public record EmojiGherXunitLexer : IGherXunitLexer
{
public (string Key, string Value)[] Given => [("Given", "\ud83d\ude10")];
public (string Key, string Value)[] When => [("When", "\ud83c\udfac")];
public (string Key, string Value)[] Then => [("Then", "\ud83d\ude4f")];
public (string Key, string Value)[] And => [("And", "\ud83d\ude02")];
public string Background => "\ud83d\udca4";
public string Scenario => "\ud83e\udd52\ud83d\udcd5";
public string Feature => "\ud83d\udcda";
}
```
The Gherkin provides two built-in lexers: `Lexers.PtBr` for Portuguese (🇵🇹🇧🇷) and `Lexers.EnUs` for English (🇺🇸).
You can also create your custom lexer by implementing the `IGherXunitLexer` interface. To use the custom lexer,
you need to pass it as a parameter when defining the test scenario.

## 📚 References

- 📖 **Farooq, M. S., et al. (2023). Behavior Driven Development**: *A Systematic Literature Review. IEEE* Access. DOI: [10.1109/ACCESS.2023.3302356](https://doi.org/10.1109/ACCESS.2023.3302356).
- 📖 **North, D. (2006)**. *Introducing BDD. DanNorth.net.* Available at: [https://dannorth.net/introducing-bdd/](https://dannorth.net/introducing-bdd/).
- 📖 **xUnit. (2023)**. *xUnit.net.* Available at: [https://xunit.net/](https://xunit.net/).
- 📖 **Gherkin. (2023)**. *Gherkin.* Available at: [https://cucumber.io/docs/gherkin/](https://cucumber.io/docs/gherkin/).

### 📌 Definindo o Lexer globalmente

A partir da versão 1.3.0, você pode definir o Lexer padrão para todos os testes do projeto (ou de uma classe) usando `GherXunitConfig.DefaultLexer`:

```csharp
[Feature("Subscribers see different articles based on their subscription level")]
public partial class LocalizationTest
{
// Using Portuguese (🇵🇹🇧🇷) lexer
static LocalizationTest()
{
GherXunitConfig.DefaultLexer = Lexers.PtBr; // Define o padrão para todos os testes desta classe
}

[Scenario("Inscrever-se para ver artigos gratuitos")]
async Task WhenFriedaLogs() => await this.ExecuteAscync(
refer: WhenFriedaLogsSteps,
lexer: Lexers.PtBr,
steps: """
Dado Free Frieda possui uma assinatura gratuita
Quando Free Frieda faz login com suas credenciais válidas
Então ela vê um artigo gratuito
""");

// Using custom emoji lexer
[Scenario("Subscriber with a paid subscription can access both free and paid articles")]
// Para cenários que precisam de um lexer diferente, basta passar o parâmetro normalmente:
[Scenario("Custom emoji lexer")]
void WhenPattyLogs() => this.Execute(
refer: WhenPattyLogsSteps,
lexer: new EmojiGherXunitLexer(),
Expand All @@ -145,31 +142,5 @@ public partial class LocalizationTest
""");
}
```
The result of running the test scenarios defined in the `LocalizationTest` class using the custom lexer would be similar to the following output:
```gherkindotnet
TEST RESULT: 🟢 SUCCESS
⤷ FUNCIONALIDADE Subscribers see different articles based on their subscription level
⤷ CENARIO Inscrever-se para ver artigos gratuitos
| DADO ↘ Free Frieda possui uma assinatura gratuita
| QUANDO ↘ Free Frieda faz login com suas credenciais válidas
| ENTÃO ↘ ela vê um artigo gratuito

TEST RESULT: 🟢 SUCCESS
⤷ 📚 Subscribers see different articles based on their subscription level
⤷ 🥒📕 Subscriber with a paid subscription can access both free and paid articles
| 😐 ↘ Paid Patty has a basic-level paid subscription
| 🎬 ↘ Paid Patty logs in with her valid credentials
| 🙏 ↘ she sees a Free article and a Paid article
```

### 🔎 Is GherXunit for You?
If your team already uses xUnit and wants to experiment with a BDD approach without drastically changing its workflow, **GherXunit** may be an option to consider. It does not eliminate all BDD challenges but seeks to facilitate its adoption in environments where xUnit is already widely used.
See more usage examples and implementation details for `Background`, `Rule`, `Features`, and other elements in the [sample code](/src/base/GherXunit.Core/Samples) available in the **GherXunit** repository.


## 📚 References

- 📖 **Farooq, M. S., et al. (2023). Behavior Driven Development**: *A Systematic Literature Review. IEEE* Access. DOI: [10.1109/ACCESS.2023.3302356](https://doi.org/10.1109/ACCESS.2023.3302356).
- 📖 **North, D. (2006)**. *Introducing BDD. DanNorth.net.* Available at: [https://dannorth.net/introducing-bdd/](https://dannorth.net/introducing-bdd/).
- 📖 **xUnit. (2023)**. *xUnit.net.* Available at: [https://xunit.net/](https://xunit.net/).
- 📖 **Gherkin. (2023)**. *Gherkin.* Available at: [https://cucumber.io/docs/gherkin/](https://cucumber.io/docs/gherkin/).
> **Dica:** O parâmetro `lexer` só precisa ser informado no teste se você quiser sobrescrever o padrão global.
2 changes: 1 addition & 1 deletion src/base/GherXunit.Core/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static void Write(this IGherXunitStep scenario, string? methodName, stri
? $"{(isBackground ? "Background" : "Scenario")} {methodName}\r\n"
: $"{(isBackground ? "Background" : "Scenario")} {iTest.DisplayName}\r\n";

var stepString = new StringHandler(lexer ?? Lexers.EnUs);
var stepString = new StringHandler(lexer ?? GherXunitConfig.DefaultLexer ?? Lexers.EnUs);
stepString.AppendLiteral($"{statusResult}{featuresText}{scenarioText}{steps}");

output?.WriteLine(".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ namespace BddTests.Samples.Localization;
[Feature("Subscribers see different articles based on their subscription level")]
public partial class LocalizationTest
{
static LocalizationTest()
{
GherXunitConfig.DefaultLexer = Lexers.PtBr;
}

[Scenario("Inscrever-se para ver artigos gratuitos")]
async Task WhenFriedaLogs() => await this.ExecuteAscync(
refer: WhenFriedaLogsSteps,
lexer: Lexers.PtBr,
steps: """
Dado Free Frieda possui uma assinatura gratuita
Quando Free Frieda faz login com suas credenciais válidas
Expand Down
5 changes: 5 additions & 0 deletions src/base/GherXunit.Core/StringHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ public record PtBrGherXunitLexer : IGherXunitLexer
public string Background => "CONTEXTO";
public string Scenario => "CENARIO";
public string Feature => "FUNCIONALIDADE";
}

public static class GherXunitConfig
{
public static IGherXunitLexer? DefaultLexer { get; set; }
}
2 changes: 1 addition & 1 deletion src/lib/GherXunit/GherXunit.Content.Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static void Write(this IGherXunitStep scenario, string? methodName, stri
? $"{(isBackground ? "Background" : "Scenario")} {methodName}\r\n"
: $"{(isBackground ? "Background" : "Scenario")} {iTest.DisplayName}\r\n";

var stepString = new StringHandler(lexer ?? Lexers.Default);
var stepString = new StringHandler(lexer ?? GherXunitConfig.DefaultLexer ?? Lexers.Default);
stepString.AppendLiteral($"{statusResult}{featuresText}{scenarioText}{steps}");

output?.WriteLine(".");
Expand Down
5 changes: 5 additions & 0 deletions src/lib/GherXunit/GherXunit.Content.StringHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,10 @@ public record PtBrGherXunitLexer : IGherXunitLexer
public string Scenario => "CENARIO";
public string Feature => "FUNCIONALIDADE";
}

public static class GherXunitConfig
{
public static IGherXunitLexer? DefaultLexer { get; set; }
}
""";
}
2 changes: 1 addition & 1 deletion src/lib/GherXunit/GherXunit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<PackageId>GherXunit</PackageId>
<Version>1.2.0</Version>
<Version>1.3.0</Version>
<Authors>Yan Justino</Authors>
<Company>Emergingcode</Company>
<Description>GherXunit emerges as a viable alternative for those seeking an approach that combines the expressiveness of BDD with the well-established structure of xUnit.</Description>
Expand Down