Jump to content
Ugochukwu Mmaduekwe

Running UnitTests for Mobile Devices

Recommended Posts

How do you all test your codebase especially those that use DUnit Testing Framework on mobile devices like Android and iOS.
I still do it the old fashion way, compile the demo project with the tests and execute them on my device.
while the above works, it's to say the least very stressful.
Are there better ways to test my code with DUnit on mobile devices something like a DUnit GUI TestRunner for FMX?

Thanks.

Share this post


Link to post

The way we do it is we created a small class to inherit from ITestListener and ITestListenerX that acts like a simple remote TCP client on the mobile device to intercept the results of the tests as they happen and a simple TCP server with a GUI on Windows using Indy that the client connects to display the tests.

  • Like 2

Share this post


Link to post
2 minutes ago, Allen@Grijjy said:

The way we do it is we created a small class to inherit from ITestListener and ITestListenerX that acts like a simple remote TCP client on the mobile device to intercept the results of the tests as they happen and a simple TCP server with a GUI on Windows using Indy that the client connects to display the tests.

wow, this is way over my head.
do you have any sample code demo please?

Share this post


Link to post

Sorry, the code is so tightly coupled with our private code, it would take some time to decouple the pieces.  We may do a blog article on this in the future on our site, blog.grijjy.com.  The approach we took is to use the example ITestRunner that are included with Delphi samples and just intercept the test results and send them over the wire.  You could use almost any communication library to send them, or even log them locally if you want to avoid that step.

  • Thanks 2

Share this post


Link to post
On 2/2/2019 at 4:57 PM, Allen@Grijjy said:

The way we do it is we created a small class to inherit from ITestListener and ITestListenerX that acts like a simple remote TCP client on the mobile device to intercept the results of the tests as they happen and a simple TCP server with a GUI on Windows using Indy that the client connects to display the tests.

That's exactly what TestInsight does...

Share this post


Link to post
1 hour ago, Stefan Glienke said:

https://bitbucket.org/sglienke/testinsight/wiki/Home

 

On mobile you need a bare UI application though iirc - just make a form with a button that calls RunRegisteredTests.

Either hardcode the uri to your developer machine or deploy the TestInsightSettings.ini that gets written next to the binary.

@Stefan Glienke So I did this
1. Connected my Android Phone and PC to the Same Local Network (MY MiFi)

2. Created a simple FMX app to run my tests and in the buttonClick Event, I added

TestInsight.DUnit.RunRegisteredTests('http://IP:8103');

Where IP is the IP Address gotten from TestInsight.ini file

3. Compiled the simple app for Windows, ran it and clicked the button, voila, it triggers the TestInsight plugin and I can see the tests run and report it's result on the plugin.

4. Recompiled the simple app for Android, installed, ran it and clicked the button, nothing happen, the button indicates that it is waiting for something, app is stuck but no indication/notification that the tests are running on the TestInsight plugin on my IDE. 

 

What's wrong?

Any other suggestions please?

Share this post


Link to post
28 minutes ago, Stefan Glienke said:

Run it under the debugger so see where it's stuck?

@Stefan Glienke

ok, so I tried debugging it but got a strange error related to unable to open socket, so I decided to do it the old fashioned way, Logging, I edited the file TestInsight.DUnit.pas and placed markers in the method 

procedure RunRegisteredTests(const baseUrl: string);

to know if the tests executes at least and I discovered that it did but unfortunately for some strange reasons, it doesn't report it's progress back to TestInsight IDE Plugin, I don't know why it behaves so.

Share this post


Link to post

so from what I can deduce, the connection back to the plugin on my PC via my IP Is not working on Android, can't seem to figure out why.

The annoying thing is that it works fine when I compile it and run my test project on Windows.

Edited by Ugochukwu Mmaduekwe

Share this post


Link to post
2 hours ago, Ugochukwu Mmaduekwe said:

so from what I can deduce, the connection back to the plugin on my PC via my IP Is not working on Android, can't seem to figure out why.

The annoying thing is that it works fine when I compile it and run my test project on Windows.

I believe you need to open the ports that TestInsight is listening to

Share this post


Link to post

There is the IDE plugin that listens on the TCP port(range) specified in its settings and the client that is compiled into the test projects sends its result to it. What exactly should not work about that on any platform that can do TCP/IP?

Share this post


Link to post
Just now, John Kouraklis said:

When you run the tests from TI, does it use the selected platform or only Win32? 

It basically does what "Run" does.

Share this post


Link to post
8 minutes ago, Ugochukwu Mmaduekwe said:

On my Android or PC?

Probably on both as TI uses a non-standard port

 

But I don't know how to do it on Android. If you find out please share. I am interested

Share this post


Link to post
4 hours ago, John Kouraklis said:

But I don't know how to do it on Android. If you find out please share. I am interested

@John Kouraklis

Finally got it to work, below are the steps.

1. Download Angry Port Scanner from Google PlayStore (Do not open)
2. connect your PC and Android to the same WiFi network

3. Open Angry Port Scanner, it will auto select the IP range to scan, in the Ports edit box enter the value 8000-9000 and click the scan icon

4. after the scan is done, it will show you the Open IP and Port, this is the IP and Port we will put in our FMX app.

5. Create a simple GUI FMX app with a button and the tests you want to execute.

6. in the uses clause add (TestInsight.DUnit) , in the OnClick event of the button, add the code below

TestInsight.DUnit.RunRegisteredTests('http://IP:PORT');

where IP and PORT are the values we got previously.

7. Compile and deploy the FMX app to your android device, run and click the button

8. go back to your Delphi IDE and open the TestInsight Plugin, you can now see the progress of your Tests.

 

Thanks to everyone who pointed to the right directions that helped me solve this problem.

  • Like 2
  • Thanks 1

Share this post


Link to post

There is a different approach. I like the approach of DUnit running on Windows under VCL.

How can you get the Green Light paradigm working on FMX?

 

Well, Roger Connell has done the port to FMX.

 

See  http://docs.innovasolutions.com.au/Docs/ADUGDelphi/ADUGDecember2014.html

 

This approach was presented to ADUG in December 2014.

I have used it successfully on Android under FMX. It works very well.

  • Like 3

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×