VBA-tools / vba-test

Add testing and TDD to VBA on Windows and Mac
MIT License
202 stars 46 forks source link

Add Suite Grouping #27

Closed timhall closed 5 years ago

timhall commented 6 years ago

The goal here is that reporters only take in a single TestSuite, but for added flexibility TestSuite can contain any number of arbitrarily nested TestSuite groups. This should simplify the API for WorkbookReporter and allow different ways of defining tests.

Dim Suite As New TestSuite
Suite.Name = "Project Name"

' BeforeEach / AfterEach called for all tests
Fixture.ListenTo Suite

With Suite.Group("Module Name")
  With Suite.Group("Part 1")
    ' BeforeEach / AfterEach just for "Part 1"
    Part1Fixture.ListenTo .Self

    With .Test("Test 1")
      .IsEqual 2 + 2, 4
    End With
  End With
End With

This allows for separating tests and suites among different functions / files.

Dim Suite As New TestSuite
Suite.Name = "Project Name"

ModuleA.Tests Suite.Group("Module A")

With Suite.Group("Module B")
  ModuleB.Test1 .Test("Test 1")
  ModuleB.Test2 .Test("Test 2")
End With
connerk commented 5 years ago

I can't get blocks to build...

connerk commented 5 years ago

The current test suite doesn't test WorkbookReporter which is labeled at the top as a primary benefactor of the changes.

I've tried altering the Tests.RunTests() a bit to wedge everything into a single test suite but can't seem to get the syntax right.

so far, a couple different directions that seem logical but don't work:

Public Function RunTests() As TestSuite

    Dim wbr As New WorkbookReporter
    wbr.ConnectTo ThisWorkbook.Sheets(1)
    wbr.Start 1

    wbr.Output NestedTests

    wbr.Done
End Function

Private Function NestedTests() As TestSuite
    Dim ts As New TestSuite
    ts.Name = "RunTests"

    Dim TCase As TestCase

    With ts.Group("TestSuite Tests")
        Dim TTS As TestSuite
        Set TTS = Tests_TestSuite.Tests

        For Each TCase In TTS.Tests
            .Test(TCase.Name).Self = TCase
        Next TCase

    End With
    With ts.Group("TestCase Tests")
        Dim TTC As TestSuite
        Set TTC = Tests_TestCase.Tests

        For Each TCase In TTS.Tests
            TCase .Test(TCase.Name)
        Next TCase

    End With

    Set NestedTests = ts

End Function

sorry! trying to be helpful and contribute. how can I get this tested before approving the PR?

Thanks Tim!

timhall commented 5 years ago

Temporarily removed WorkbookReporter, will add it back in a later PR