Android Question How do I create an unit test in b4a?

davepamn

Active Member
Licensed User
Longtime User
I need to create an unit test for my functions. What is the best way to create the unit tests
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Write them? Sorry, I guess I don't understand.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Create your fuctions in a class module and call/test them from the main module. Search for the tutorial on what is a class module and how to work with them
 
Last edited:
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
I know class models.

How do I call the unit test main function from the app? Do I create a menu item called "unit test"? I don't want the users to see the unit test feature
 
Upvote 0

ArminKH

Well-Known Member
If u want to create default function you should edit core library
But i'm not sure that i understand
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
It seems like the tool should have a button called run "Unit Test" that I can call my functions in the project and test their output
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Classes are reusable pieces of code, the main difference between classes and code modules is that a class can generate and interact with UI elements, and code modules cannot.

You can import your Function module (class or code module) into a new project and test its functions. after you're happy with it, use the module in the final app.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
when I try debugging a Class, if its not a CustomView, I mainly use LogColor with the new smartstring literal $" "$.
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
So I import the class into the test project and then create a UI to display the results of the test

Do you build [one] Unit Test Project that manages the unit testing for all your B4A projects?
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
Will you provide the steps for importing the class into the Unit Test project?

"Add Existing Modules"?
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
that seems to work. I am going to create an interface for displaying the test results.

If I make changes in the production code than it will need to be reimported into the test project.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
exactly that. I recommend you to create a "shared modules" folder and add it to your B4A Paths
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
tools->Path Configuration->Shared Modules

Do I have to import the .bas files after defining the Share Module directory?
 
Last edited:
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
As I understand the shared file scenario, the abc.bas file is referenced by two projects. The fact that I put the shared file in the Shared Modules path configuration tells the compiler to use the code in an external location other than under the project directory.


My shared code compiled and install, ok.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
As I understand the shared file scenario, the abc.bas file is referenced by two projects. The fact that I put the shared file in the Shared Modules path configuration tells the compiler to use the code in an external location other than under the project directory.

No, its just tells the IDE where to first look for Module files. A Module file (the .bas), can be in use by n projects.
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
When I added the path to the shared modules, the two modules I put in the folder were not discovered. I had to import them into the project.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Correct, the only difference is, you don't need to replicate your module unless you need to, like in the case you make changes that you don't want to stay in the original shared module. Modules you import from the Shared modules folder stay in the shared modules folder, they are not copied to your project folder, so if you have a module that is used in several projects, any change made to the module will reflect in all projects.
 
Upvote 0

davepamn

Active Member
Licensed User
Longtime User
shared modules are pretty cool. I made a change in one project in the shared code module then open up the other project and the changes were in the code.
 
Upvote 0
Top