advpl-testsuite
advpl-testsuite copied to clipboard
Reduce verbosity
This PR introduces a less verbose way to create tests by creating a easier way to define a testsuite and a more natural way to express fluent expectations.
Old test definition:
#include 'protheus.ch'
#include 'testsuite.ch'
TestSuite Expect Description 'The test suite to test the test suite itself!' Verbose
Enable Environment 'T3' 'S SC 01'
Enable Before
Feature Files Description 'Tests with files should be working'
Feature Folders Description 'Tests with folders should be :top:'
EndTestSuite
Before TestSuite Expect
If File( '\love.txt' )
FErase( '\love.txt' )
EndIf
If ExistDir( '\problems' )
DirRemove( '\problems' )
EndIf
Return
Feature Files TestSuite Expect
Local nHandle
nHandle := FCreate( '\love.txt' )
FWrite( nHandle, 'I love you <3' )
FClose( nHandle )
::Expect( nHandle ):Not():ToHaveType( 'C' )
::Expect( nHandle ):ToHaveType( 'N' )
::Expect( nHandle ):Not():ToBe( 0 )
::Expect( '\hate.txt' ):Not():ToBeAfile()
::Expect( '\love.txt' ):ToBeAFile()
::Expect( '\love.txt' ):Not():ToBeAFileWithContents( 'I hate you :@' )
::Expect( '\love.txt' ):ToBeAFileWithContents( 'I love you <3+' )
Return
Feature Folders TestSuite Expect
MakeDir( '\problems' )
::Expect( '\problems' ):ToBeAFolder()
::Expect( '\happiness' ):Not():ToBeAFolder()
Return
CompileTestSuite Expect
New test definition:
#define SUITEID Expect
Test Suite 'The test suite to test the test suite itself!' Verbose
Define Before
If File( '\love.txt' )
FErase( '\love.txt' )
EndIf
If ExistDir( '\problems' )
DirRemove( '\problems' )
EndIf
Return
Define Feature Files 'Tests with files should be working'
Local nHandle
nHandle := FCreate( '\love.txt' )
FWrite( nHandle, 'I love you <3' )
FClose( nHandle )
Expect nHandle to not have type 'C'
Expect nHandle to have type 'N'
Expect nHandle to not be 0
Expect '\hate.txt' to not be a file
Expect '\love.txt' to be a file
Expect '\love.txt' to not be a file with contents 'I hate you :@'
Expect '\love.txt' to be a file with contents 'I love you <3+'
Return
Define Feature Folders 'Tests with folders should be :top:'
MakeDir( '\problems' )
Expect '\problems' to be a folder
Expect '\happiness' to not be a folder
Return
End Test Suite
#undef SUITEID
I made it in a way it wouldn't affect existing tests but, if you like it, I can make it the only way to write the tests.
@haskellcamargo Any thoughts on this?