accesscodelib / accunit Goto Github PK
View Code? Open in Web Editor NEWAccUnit - Test your VBA/Access code
Home Page: https://accunit.access-codelib.net/
License: GNU General Public License v3.0
AccUnit - Test your VBA/Access code
Home Page: https://accunit.access-codelib.net/
License: GNU General Public License v3.0
The installation has worked up to the point in the Video where one type
TestSuite.name in the window
I loaded the database TestRunner.accdb
While trying to tun the test I just get:
Der Typ 'AccessCoddLib.common.VBIDETools.CodeModuleMember in der Assembly "AccessCodLib.VBIDETools,Version=0.9.10.0, Culture=Neutral, PublicKeyToken=null konnte nicht geladen werden
And that's it ...
possible Interface:
Filter with tags:
TestSuite.AddByClassName("TestClassName").Filter("abc", "xyz", "123").Run
TestSuite.Add(new TestClass).Filter(...).Run
TestSuite.AddFromVBProject.Filter(...).Run
Filter method name:
Extend Add methods
TestSuite.AddByClassName("TestClassName", Array("MethodName1", "MethodName2")).Run
TestSuite.Add(new TestClass, ."*Xyz*").Run
TestSuite.AddFromVBProject ...
... Method filtering is rather unusual here, why would you want to run a particular method in multiple test classes?example:
Dim Actual() As Variant
Dim Expected() As Variant
Assert.AreEqual Expected, Actual
=> out of memory
missing type info in AccUnit.tlb for VbProject.
The test classes should be able to be imported and exported automatically from a specified directory.
Log test results to VCS
e. g. Assert.That Clng(1), Iz.Strict.EqualTo(Cdbl(1)) ...should fail
Example test code: (from https://github.com/AccessCodeLib/AccessCodeLib/blob/master/_test/data/dao/DaoHandlerTests.cls)
Public Sub CreateParamDefArray_Use4ParamArrays_CheckArray()
Dim Actual() As Variant
Dim Expected(3, 1) As Variant
Dim i As Long
For i = 0 To 3
Expected(i, 0) = i
Expected(i, 1) = i * 2 + 1
Next
Actual = m_DaoHandler.GetParamDefArray(1, 3, 5, 7)
Assert.AreEqual Expected, Actual
End Sub
Result:
Error: At least one object must implement IComparable.
Issue:
Call Export TestClasses: codemodules marked with AccUnit:TestRelated not exported
A test with ChatGPT returned a usable result.
Prompt:
I aim to create a test procedure that uses row-test definitions similar to NUnit.
I work with VBA in Access and utilize the AccUnit testing framework.
I expect each AccUnit:Row entry to be treated as a separate test case, and for the test results to be checked directly within the test method itself.
Please use the following format for the test:'AccUnit:Row(...).Name(...) 'AccUnit:Row(...) Public Sub TestMethod(...) ' Arrange ... ' Act ... ' Assert Assert.That ... End Sub
Parameters should be directly included in the signature of the test procedure. Also use an Expected parameter and define the value in the test row definition. Set optional parameters to required.
The AccUnit:Row annotations should be defined outside the procedure.
Note for assert: since Is is not allowed as a variable in VBA, the framework uses Iz (e.g. for Iz.EqualTo) as a substitute.
Please create a test procedure for the following method from the SqlTools class:'--------------------------------------------------------------------------------------- ' Function: BuildCriteria '--------------------------------------------------------------------------------------- '/** ' <summary> ' Create SQL criteria string ' </summary> ' <param name="FieldName">Field name in the data source to be filtered</param> ' <param name="RelationalOperator">Relational operator (=, <=, etc.)</param> ' <param name="FilterValue">Filter value (can be a single value or an array of values)</param> ' <param name="FilterValue2">Optional 2nd filter value (for Between)</param> ' <param name="IgnoreValue">The value for which no filter condition is to be created. (Array transfer of values possible)</param> ' <returns>String</returns> ' <remarks> ' </remarks> '**/ '--------------------------------------------------------------------------------------- Public Function BuildCriteria(ByVal FieldName As String, ByVal FieldDataType As SqlFieldDataType, _ ByVal RelationalOperator As SqlRelationalOperators, _ ByVal FilterValue As Variant, _ Optional ByVal FilterValue2 As Variant = Null, _ Optional ByVal IgnoreValue As Variant, _ Optional ByVal DisableIgnoreNullValue As Boolean = False) As String ... End Function Public Enum SqlRelationalOperators [_IgnoreAll] = &H80000000 SQL_Not = 1 SQL_Equal = 2 SQL_LessThan = 4 SQL_GreaterThan = 8 SQL_Like = 256 SQL_Between = 512 SQL_In = 1024 SQL_Add_WildCardSuffix = 2048 SQL_Add_WildCardPrefix = 4096 SQL_SplitValueToArray = 8192 SQL_AllowSqlDirect = 16384 SQL_UseLikeBehavior = 65536 End Enum Public Enum SqlFieldDataType SQL_Boolean = 1 SQL_Numeric = 2 SQL_Text = 3 SQL_Date = 4 End Enum
Return only the code without explanation.
Result:
'AccUnit:Row("CustomerID", SQL_Text, SQL_Equal, "1001", Null, Null, "CustomerID = '1001'").Name("TestEqualText")
'AccUnit:Row("OrderAmount", SQL_Numeric, SQL_GreaterThan, 500, Null, Null, "OrderAmount > 500").Name("TestGreaterThanNumeric")
'AccUnit:Row("OrderDate", SQL_Date, SQL_Between, #1/1/2020#, #12/31/2020#, Null, "OrderDate BETWEEN #1/1/2020# AND #12/31/2020#").Name("TestBetweenDates")
'AccUnit:Row("ProductName", SQL_Text, SQL_Like, "%milk%", Null, Null, "ProductName LIKE '%milk%'").Name("TestLikeText")
Public Sub TestBuildCriteria(ByVal FieldName As String, ByVal FieldDataType As SqlFielddataType, _
ByVal RelationalOperator As SqlRelationalOperators, ByVal FilterValue As Variant, _
ByVal FilterValue2 As Variant, ByVal IgnoreValue As Variant, ByVal Expected As String)
' Arrange
Dim sqlTools As New SqlTools
' Act
Dim result As String
result = sqlTools.BuildCriteria(FieldName, FieldDataType, RelationalOperator, FilterValue, FilterValue2, IgnoreValue)
' Assert
Assert.That(result, Iz.EqualTo(Expected))
End Sub
See: https://chat.openai.com/share/436f2ed0-2f21-4fc3-9552-94030ec2cb54
For automatic test execution (e.g. when checking in to source code management), save the results in files.
TestClassGenerator generates this code for Public Function Method1(ByVal x As Long) As Long
:
'AccUnit:Row(x, Expected).Name = "Example row - please replace the parameter names with values)"
Public Sub Method1(ByVal x As Long, ByVal Expected As Long)
' Arrange
Err.Raise vbObjectError, "Method1", "Test not implemented"
Const Expected As Variant = "expected value"
Dim Actual As Variant
' Act
Actual = "actual value"
' Assert
Assert.That Actual, Iz.EqualTo(Expected)
End Sub
The line Const Expected As Variant = "expected value"
should not be there. It should only be there for tests without parameters.
If an older version is installed and a new version with new interfaces is installed in tlb, AccUnitLoader.accda cannot be compiled.
to fix: check tlb version and update file
VBA enum values should become possible in the Row Test declaration to increase readability.
Actual:
'AccUnit:Row(1, #1/1/2023#) ' 1 = vbSunday
'AccUnit:Row(2, #1/1/2024#) ' 2 = vbMonday
Public Sub MyFirstTest(ByVal Expected As VbDayOfWeek, ByVal DateToCheck As Date)
Better:
'AccUnit:Row(vbSunday, #1/1/2023#)
'AccUnit:Row(vbMonday, #1/1/2024#)
Public Sub MyFirstTest(ByVal Expected As VbDayOfWeek, ByVal DateToCheck As Date)
Insert a template via the add-in or immediate windows like TestSuite.InsertTemplate.TemplateName
Load test classes, run tests and cleanup code from outside (VB script, ...)
Originally posted by FDominicus September 21, 2023
Yes, a gui interface in which one can see the tests and choose from wich to run, would be very appreciated.
IMHO testing should not be pain, it should be easy, fast and accessible. I don't feel the output in the console is that.
vbNullstring (VBA: StrPtr = 0) is null in C#.
Add a Assert methode to compare strings (with string parameters for actual/expected)
Possible variants (interface for VBA):
Assert.AreEqual Expected, Actual, "InfoText", ++ string compare parameter ++
Assert.StringCompare(IgnoreCase:=False, VbNullStringEqualEmptyString:=True).AreEqual Expected, Actual
Assert.StringCompare(Compare:= vbTextCompare).AreEqual Expected, Actual
Assert.StringCompare(....).That Actual, Iz.EqualTo(Expected)
Note: Maybe this is useful for other data types as well.
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.