Fluent VBA is an object-oriented fluent unit testing library for VBA. This project was inspired by Fluent Assertions in C#.
Fluent APIs are intended to be read like natural language. So instead of having something like:
Option Explicit
Sub NormalUnitTestExample
Dim result as long
Dim Assert as cUnitTester
'//Arrange
Set Assert = New cUnitTester
'//Act
result = returnVal(5) 'returns the value provided as an argument
'//Assert
Assert.Equal(Result,5)
End Sub
Public Function returnVal(ByVal value As Variant) As Variant
returnVal = value
End Function
You can have code that reads more naturally like so:
Option Explicit
Sub FluentUnitTestExample1
Dim Result As cFluent
Dim returnedResult As Variant
'//Arrange
Set Result = New cFluent
returnedResult = returnVal(5)
'//Act
Result.TestValue = returnedResult
'//Assert
Debug.Assert Result.Should.Be.EqualTo(5)
Debug.Assert Result.Should.Be.GreaterThan(4)
End Sub
Or, arguably, even more naturally using cFluentOf objects like this:
Option Explicit
Sub FluentUnitTestExample2()
Dim Result As cFluentOf
Dim returnedResult As Variant
'//arrange
Set Result = New cFluentOf
returnedResult = returnVal(5)
'//Act
With Result.Of(returnedResult)
'//Assert
Debug.Assert .Should.Be.EqualTo(5)
Debug.Assert .Should.Be.GreaterThan(4)
End With
'//Or like this
'//Act & Assert
Debug.Assert Result.Of(returnedResult).Should.Be.EqualTo(5)
Debug.Assert Result.Of(returnedResult).Should.Be.GreaterThan(4)
End Sub
To get started with Fluent VBA you can see the getting started page on the wiki.
You can contact me at [email protected].
I'm open to external contributions for Fluent VBA. I do need to work on a style guide to determine how I'd like such contributions to be implemented. I also expect any contributions to have unit tests using the Fluent VBA library.
You are free to contact me regarding feature requests as long as you understand that I'm not obligated to implement them. I expect messages to be polite, respectful, and without a sense of entitlement. As long as you do those things, I'm happy to hear what you have to say.
The API is in a good and usable state. Overall I'm pretty happy with the API's internal and external design. As of right now, I only anticipate internal changes and feature enhancements. So the design of the API should be relatively stable. I'd be open to changing certain design aspects of the API if I found a good reason to do so. Naturally, this is dependant on time and availability on my part however.