Skip to content

Commit c9986f5

Browse files
committed
Rename to VBA-TDD
1 parent 4cd337d commit c9986f5

File tree

9 files changed

+85
-66
lines changed

9 files changed

+85
-66
lines changed

README.md

Lines changed: 77 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
Excel-TDD: Excel Testing Library
2-
================================
1+
VBA-TDD
2+
=======
33

4-
Bring the reliability of other programming realms to Excel with Test-Driven Development for Excel.
4+
Bring the reliability of other programming realms to VBA with Test-Driven Development (TDD) for VBA on Windows and Mac.
55

66
Quick example:
77

8-
```VB.net
9-
Sub Specs()
10-
On Error Resume Next
8+
```vb
9+
Function Specs() As SpecSuite
10+
Set Specs = New SpecSuite
11+
Specs.Description = "Add"
1112

12-
' Create a new collection of specs
13-
Dim Specs As New SpecSuite
13+
' Report results to the Immediate Window
14+
' (ctrl + g or View > Immediate Window)
15+
Dim Reporter As New ImmediateReporter
16+
Reporter.ListenTo Specs
1417

1518
' Describe the desired behavior
1619
With Specs.It("should add two numbers")
@@ -24,8 +27,6 @@ Sub Specs()
2427
.Expect(Add(1, 2, 3)).ToEqual 6
2528
.Expect(Add(1, 2, 3, 4)).ToEqual 10
2629
End With
27-
28-
InlineRunner.RunSuite Specs
2930
End Sub
3031

3132
Public Function Add(ParamArray Values() As Variant) As Double
@@ -37,68 +38,31 @@ Public Function Add(ParamArray Values() As Variant) As Double
3738
Next i
3839
End Function
3940

40-
' Open the Immediate Window (Ctrl+g or View > Immediate Window) and Run Specs (F5)'
41-
' = PASS (2 of 2 passed) ==========================
41+
' Immediate Window:
42+
'
43+
' === Add ===
44+
' + should add two numbers
45+
' + should add any number of numbers
46+
' = PASS (2 of 2 passed) =
4247
```
4348

44-
For details of the process of reaching this example, see the [TDD Example](https://github.com/timhall/Excel-TDD/wiki/TDD-Example)
49+
For details of the process of reaching this example, see the [TDD Example](https://github.com/VBA-tools/VBA-TDD/wiki/TDD-Example)
4550

4651
### Advanced Example
4752

48-
For an advanced example of what is possible with Excel-TDD, check out the [specs for Excel-REST](https://github.com/timhall/Excel-REST/tree/master/specs)
49-
50-
Methods used in these specs:
51-
52-
- Using `BeforeEach` to reset before each spec is run
53-
- Testing VBA modules and classes
54-
- Setting up a custom `DisplayRunner` and `InlineRunner`
55-
- Waiting for and handling async behavior
53+
For an advanced example of what is possible with VBA-TDD, check out the [specs for VBA-Web](https://github.com/VBA-tools/VBA-Web/tree/master/specs)
5654

5755
### Getting Started
5856

59-
For testing macros:
60-
61-
- The lightweight Inline Runner is recommended and should be added directly to the workbook that is being tested
62-
- Add `InlineRunner.bas`, `SpecDefinition.cls`, `SpecExpectation.cls`, and `SpecSuite.cls` to your workbook
63-
- If starting from scratch, the `Excel-TDD - Blank - Inline.xlsm` workbook includes all of the required classes and modules
64-
65-
For testing workbooks:
66-
67-
- The full Workbook Runner is recommended in order to keep testing behavior separate from the workbook that is being tested
68-
- Use the `Excel-TDD - Blank.xlsm` workbook
69-
- See the [Workbook Runner Example](https://github.com/timhall/Excel-TDD/wiki/Workbook-Runner-Example) for details
70-
71-
### Inline Runner
72-
73-
The inline runner is a lightweight test runner that is intended to be loaded directly into the workbook that is being tested and is for testing macros and simple behaviors in the workbook
74-
All results are displayed in the Immediate Window (Ctrl+g or View > Immediate Window) and the runner requires no setup to run test suites
75-
76-
```VB.net
77-
InlineRunner.RunSuite Specs
78-
79-
' = PASS (2 of 2 passed) ==========================
80-
81-
' Configurable
82-
InlineRunner.RunSuite Specs, ShowFailureDetails:=True, ShowPassed:=True, ShowSuiteDetails:=True
83-
84-
' = PASS (2 of 2 passed) ==========================
85-
' + 2 specs
86-
' + should add two numbers
87-
' + should add any number of numbers
88-
' ===
89-
```
90-
91-
### Workbook Runner
92-
93-
The workbook runner is a full test runner that is intended to be used separately of the workbook that is being tested to keep testing behavior separate.
94-
It is for testing advanced workbook behaviors and allows for reseting the test workbook between tests, using scenarios for tests (see below), and running tests against different test workbooks.
95-
See the [Workbook Runner Example](https://github.com/timhall/Excel-TDD/wiki/Workbook-Runner-Example) for details
57+
1. Download the [latest release (v2.0.0-beta)](https://github.com/VBA-tools/VBA-TDD/releases)
58+
2. Add `src/SpecSuite.cls`, `src/SpecDefinition.cls`, `src/SpecExpectation.cls`, add `src/ImmediateReporter.cls` to your project
59+
3. If you're starting from scratch with Excel, you can use `VBA-TDD - Blank.xlsm`
9660

9761
### It and Expect
9862

9963
`It` is how you describe desired behavior and once a collection of specs is written, it should read like a list of requirements.
10064

101-
```VB.net
65+
```vb
10266
With Specs.It("should allow user to continue if they are authorized and up-to-date")
10367
' ...
10468
End With
@@ -110,7 +74,7 @@ End With
11074

11175
`Expect` is how you test desired behavior
11276

113-
```VB.net
77+
```vb
11478
With Specs.It("should check values")
11579
.Expect(2 + 2).ToEqual 4
11680
.Expect(2 + 2).ToNotEqual 5
@@ -155,7 +119,59 @@ With Specs.It("should test complex things")
155119
End With
156120
```
157121

158-
For more details, check out the [Wiki](https://github.com/timhall/Excel-TDD/wiki)
122+
### ImmediateReporter
123+
124+
With your specs defined, the easiest way to display the test results is with `ImmediateReporter`. This outputs results to the Immediate Window (`ctrl+g` or View > Immediate Window) and is useful for running your tests without leaving the VBA editor.
125+
126+
```vb
127+
Public Function Specs As SpecSuite
128+
Set Specs = New SpecSuite
129+
Specs.Description = "..."
130+
131+
' Create reporter and attach it to these specs
132+
Dim Reporter As New ImmediateReporter
133+
Reporter.ListenTo Specs
134+
135+
' -> Reporter will now output results as they are generated
136+
End Function
137+
```
138+
139+
### RunMatcher
140+
141+
For VBA applications that support `Application.Run` (which is at least Windows Excel, Word, and Access), you can create custom expect functions with `RunMatcher`.
142+
143+
```vb
144+
Public Function Specs As SpecSuite
145+
Set Specs = New SpecSuite
146+
147+
With Specs.It("should be within 1 and 100")
148+
.Expect(50).RunMatcher "ToBeWithin", "to be within", 1, 100
149+
' ^ Actual
150+
' ^ Public Function to call
151+
' ^ message for matcher
152+
' ^ 0+ Args to pass to matcher
153+
End With
154+
End Function
155+
156+
Public Function ToBeWithin(Actual As Variant, Args As Variant) As Variant
157+
If UBound(Args) - LBound(Args) < 1 Then
158+
' Return string for specific failure message
159+
ToBeWithin = "Need to pass in upper-bound to ToBeWithin"
160+
Else
161+
If Actual >= Args(0) And Actual <= Args(1) Then
162+
' Return true for pass
163+
ToBeWithin = True
164+
Else
165+
' Return false for fail or custom failure message
166+
ToBeWithin = False
167+
End If
168+
End If
169+
End Function
170+
```
171+
172+
To avoid compilation issues on unsupported applications, the compiler constant `EnableRunMatcher` in `SpecExpectation.cls` should be set to `False`.
173+
174+
For more details, check out the [Wiki](https://github.com/VBA-tools/VBA-TDD/wiki)
159175

160176
- Design based heavily on the [Jasmine](http://pivotal.github.com/jasmine/)
161177
- Author: Tim Hall
File renamed without changes.

specs/Excel-TDD - Specs.xlsm

-91.4 KB
Binary file not shown.

specs/VBA-TDD - Specs.xlsm

91.5 KB
Binary file not shown.

src/ImmediateReporter.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Attribute VB_PredeclaredId = False
99
Attribute VB_Exposed = True
1010
''
1111
' ImmediateReporter v2.0.0-beta
12-
' (c) Tim Hall - https://github.com/VBA-tools/Excel-TDD
12+
' (c) Tim Hall - https://github.com/VBA-tools/VBA-TDD
1313
'
1414
' Report results to Immediate Window
1515
'

src/SpecDefinition.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Attribute VB_PredeclaredId = False
99
Attribute VB_Exposed = True
1010
''
1111
' SpecDefinition v2.0.0-beta
12-
' (c) Tim Hall - https://github.com/VBA-tools/Excel-TDD
12+
' (c) Tim Hall - https://github.com/VBA-tools/VBA-TDD
1313
'
1414
' Collection of expectations for verifying spec
1515
'

src/SpecExpectation.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Attribute VB_PredeclaredId = False
99
Attribute VB_Exposed = True
1010
''
1111
' SpecExpectation v2.0.0-beta
12-
' (c) Tim Hall - https://github.com/VBA-tools/Excel-TDD
12+
' (c) Tim Hall - https://github.com/VBA-tools/VBA-TDD
1313
'
1414
' Provides various tests that can be performed for a provided value
1515
'

src/SpecSuite.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Attribute VB_PredeclaredId = False
99
Attribute VB_Exposed = True
1010
''
1111
' SpecSuite v2.0.0-beta
12-
' (c) Tim Hall - https://github.com/VBA-tools/Excel-TDD
12+
' (c) Tim Hall - https://github.com/VBA-tools/VBA-TDD
1313
'
1414
' A collection of specs and results
1515
'

src/WorkbookReporter.cls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ Attribute VB_PredeclaredId = False
99
Attribute VB_Exposed = True
1010
''
1111
' DisplayReporter v2.0.0-beta
12-
' (c) Tim Hall - https://github.com/VBA-tools/Excel-TDD
12+
' (c) Tim Hall - https://github.com/VBA-tools/VBA-TDD
1313
'
1414
' Report results to Worksheet
1515
'
1616
' @class DisplayReporter
17+
' @compatibility
18+
' Platforms: Windows and Mac
19+
' Applications: Excel-only
1720
' @author tim.hall.engr@gmail.com
1821
' @license MIT (http://www.opensource.org/licenses/mit-license.php)
1922
' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '

0 commit comments

Comments
 (0)