chris-peterson / kekiri Goto Github PK
View Code? Open in Web Editor NEWA .NET framework that supports writing low-ceremony BDD tests using Gherkin language
License: MIT License
A .NET framework that supports writing low-ceremony BDD tests using Gherkin language
License: MIT License
[for the wiki, or the readme]
To break up the generated fixture file into individual files for use with tools like Pickles https://github.com/picklesdoc/pickles
Create a script file: SplitFixtureFile.ps1
# From http://rafdelgado.blogspot.com/2012/06/powershell-removing-special-characters.html
Function Convert-ToFriendlyName
{
param ($Text)
# Unwanted characters (includes spaces and '-') converted to a regex:
$SpecChars = '!', '"', '£', '$', '%', '&', '^', '*', '(', ')', '@', '=', '+', '¬', '`', '\', '<', '>', '.', '?', '/', ':', ';', '#', '~', "'", '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', ' '
$remspecchars = [string]::join('|', ($SpecChars | % {[regex]::escape($_)}))
# Convert the text given to correct naming format (Uppercase)
$name = (Get-Culture).textinfo.totitlecase(“$Text”.tolower())
# Remove unwanted characters
$name = $name -replace $remspecchars, ""
$name
}
function SplitFixtureFile
{
param([string]$filepath,[string]$deployDestination)
if (Test-Path $filepath -PathType Leaf) {
$reader = new-object System.IO.StreamReader($filepath)
$filename = "NUL"
if(!(Test-Path -Path $deployDestination )){
New-Item -ItemType directory -Path $TARGETDIR
}
while(($line = $reader.ReadLine()) -ne $null)
{
if ($line.ToLower().StartsWith("fixture:") || )
{
$line -imatch "fixture: (?<content>.*)"
$fixture_name = Convert-ToFriendlyName $matches['content']
$filename = "{0}\{1}.fixture" -f ($deployDestination, $fixture_name)
}
Add-Content -path $fileName -value $line
}
$reader.Close()
}
}
SplitFixtureFile $args[0] $args[1]
And a post-build task, as follows:
<Target Name="SplitFixtureFile" Condition=" '$(WriteLogEntry)'!='false' ">
<PropertyGroup>
<PowerShellExe Condition=" '$(PowerShellExe)'=='' ">
%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe
</PowerShellExe>
<ScriptLocation Condition=" '$(ScriptLocation)'=='' ">
$(MSBuildProjectDirectory)\SplitFixtureFile.ps1
</ScriptLocation>
<FixtureFileOutputPath Condition=" '$(FixtureFileOutputPath)'=='' ">
$(MSBuildProjectDirectory)\Fixtures
</FixtureFileOutputPath>
</PropertyGroup>
<Exec Command="$(PowerShellExe) -NonInteractive -executionpolicy Unrestricted
-command "& {
&'$(ScriptLocation)'
'$(FixtureFileOutputPath)' } ""
/>
</Target>
When trying to add [Example]
to [Scenario]
, xUnit complains --
System.InvalidOperationException : [Fact] methods are not allowed to have parameters. Did you mean to use [Theory]?```
The documentation is for NUnit. Needs to be updated to XUnit (e.g. Scenario
-> Scenarios
).
Much like [Example] has a matching algorithm to tailor output based on parameter values, the Fluent Givens should support this as well (not sure if any other step types [When/Then]make sense).
the invocation of msbuild is hard-coded to v4 version of msbuild.exe, which breaks on the string interpolation in the TestGen project.
will issue PR shortly
Investigate a lower-friction alternative, e.g.
https://xunit.github.io/docs/shared-context.html#collection-fixture
Add a new extension whereby
When(xyz).Throws();
Catch<YourExceptionType>();
Could be abbreviated by When(xyz).Throws<YourException>()
A step with default values will experience runtime errors (particularly if it is a When
)
Our testing projects vary between nunit 2.6.4 and nunit 3.5
It would be useful to be able to support the nunit 3.5 projects with Kekiri in a low-friction way.
Are there any thoughts or ideas to support this? The strong name of nunit.framework has changed between 2 and 3, so an assembly redirect is out. Simply subclassing Kekiri.Test
and applying the OneTimeSetUp
and OneTimeTearDown
attributes [local to my own project] is an "almost" solution, but falls short in that the Kekiri.ThenAttribute
can't be used because of the dependency on nunit 2.6.
Creating a new ThenAttribute
class isn't an option because of the internal interface IStepAttribute
[no access to the type to implement it.]
Any ideas? A straight update to nunit 3.5 in the Kekiri solution leaves a solid portion of tests in a failing state, so any update would require additional work, for certain.
Need to have a migration guide from earlier versions of Kekiri to V4
When using Automapper with IoC, it accepts a method Func<Type, object> constructor
to specify how to construct resolvers, mappers, etc.
However, Kekiri only has T Resolve<T>()
, and no object Resolve(Type type)
Example, I would have a Given<AMockDatastore>()
which can register the datastore easily, but when I want to do a Given<MyController>()
, I can't register the type itself, only an instance, which means I would end up having to Resolve, and therefor not being able to register anything else.
XUnit runner is not detecting Scenario<T>
Due to parallelism introduced in NUnit 3.0, the preferred mechanism for emitting output is
https://github.com/nunit/docs/wiki/TestContext#writeline
Surprisingly, when defining
When(() => {})
a test will fail:
[xUnit.net 00:00:00.41] UnitTests.CustomTimestamp.DefaultBehavior [FAIL]
Failed UnitTests.CustomTimestamp.DefaultBehavior [13 ms]
Error Message:
Kekiri.Impl.Exceptions.WhenFailed : Error in 'CustomTimestamp':
'<DefaultBehavior>b 1 0' threw an exception. If this is expected behavior use .Throws() and add a step that uses Catch<>
---- System.Reflection.TargetException : Object does not match target type.
Stack Trace:
at Kekiri.Impl.ScenarioRunner.RunWhenAsync()
at Kekiri.Impl.ScenarioRunner.RunAsync()
at Kekiri.ScenarioBase.RunAsync()
at Kekiri.ScenarioBase.RunAsync()
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Kekiri.Impl.StepMethodInvoker.InvokeAsync(ScenarioBase scenario)
at Kekiri.Impl.ScenarioRunner.RunWhenAsync()
Failed! - Failed: 1
Generally, we'd prefer if a method name is provided, but it seems desirable to provide lamdas, particularly for "do nothing"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.