Jump to content
Darian Miller

Unit testing cross platform code

Recommended Posts

38 minutes ago, Darian Miller said:

 

Thanks.  I obviously didn't dig too deep... started a new Unit Test project and selected platform and there was Win32/Win64/MacOS platform options only.  I'll definitely dig in deeper!  Thanks

I guess the project wizard needs some work. I'll try and schedule some time but have a pretty full plate right now. 

  • Like 2

Share this post


Link to post
8 hours ago, Vincent Parrett said:

The readme is a bit out of date, embarcadero did contribute some changes to make it work on mobile and linux.

Unfortunately it supports only Delphi 2010 and later.

 

(Yes, I know, it's my own fault that I still use Delphi 2007, but that doesn't change the fact.)

Share this post


Link to post

DUnit runs on all platforms that Delphi supports - it just does not have the dcus shipped for each which requires adding the source directory of DUnit for those platforms (such as Linux).

I mean the core framework code, not the GUI runner of course - but I think there are some FMX out there and even if not writing your own is easy enough.

 

Running tests on Windows and Linux (and I am referring to pure unit tests) is as easy as it can be using TestInsight. Mobile can be a bit more tricky as you cannot simply shoot the app there and run it without interaction to collect the results (not 100% sure as I don't do mobile or mac development).

Edited by Stefan Glienke

Share this post


Link to post
5 hours ago, dummzeuch said:

Unfortunately it supports only Delphi 2010 and later.

I actually rate this as an advantage. Otherwise it would not be much different to the old DUnit.

Share this post


Link to post
On 10/11/2019 at 3:17 PM, Uwe Raabe said:

I actually rate this as an advantage. Otherwise it would not be much different to the old DUnit.

Everything that DUnitX does can also be achieved using DUnit (with some minor adjustments or extensions) which then makes tests that don't use features that require Delphi2010+ such as attributes still work in older versions or existing DUnit tests can be kept and just improved using new features when moving to newer Delphi versions.

Edited by Stefan Glienke
  • Like 1

Share this post


Link to post
17 minutes ago, Stefan Glienke said:

(with some minor adjustments or extensions)

What might those adjustments or extensions be?

Share this post


Link to post
7 minutes ago, Dave Nottage said:

What might those adjustments or extensions be?

https://stackoverflow.com/a/9006662/587106

 

Nowadays I suggest using https://bitbucket.org/sglienke/spring4d/src/master/Tests/Source/Spring.Testing.pas which adds the functionality mentioned in the SO answer but better than at that time and implemented in DSharp back then.

 

Two features that I personally never needed so far but that DUnitX can do which DUnit can't do out of the box are: standalone testcase classes (i.e. not inheriting from TTestCase) and per fixture setup - can also be plugged onto DUnit.

There might be other subtle features of DUnitX that I am not aware of but I am very sure that they could be added to DUnit either by inheriting or by modifying TestFramework.pas (the latter was one of the reasons Vincent rather rolled his own iirc)

Edited by Stefan Glienke
  • Like 2

Share this post


Link to post
10 hours ago, Stefan Glienke said:

Everything that DUnitX does can also be achieved using DUnit

Including FMX client screen testing and full mobile compiler support?

Share this post


Link to post
3 hours ago, Darian Miller said:

Including FMX client screen testing and full mobile compiler support?

Yes, DUnit (TestFramework.pas) compiles on all platforms that Delphi supports.

 

I think many developers don't really understand the architecture of DUnit - its just a bunch of interfaces and classes using the observer pattern to listen to events like test started, test ended, test passed, test failed. That is what things like the DUnit GUI Runner or the TestInsight client listen to - well in a nutshell, the VCL GUI runner that we all know does a bit more like allowing to select individual tests and only run those but that all works through that interface.

 

So you can implement that interface on any platform or UI or non UI framework you like.

 

All the stuff that I added to make attributes with with DUnit is just ontop - like using enhanced RTTI to discover attributes on the test case methods, read their data and create testcases from that data. Usually it uses the classic rtti looking for published methods and produces test cases from those.

Share this post


Link to post
6 hours ago, Stefan Glienke said:

TestInsight client listen to

Not entirely obvious from the FAQ etc: does TestInsight have some method of running tests on the device (or Mac machine) that are reported back to TestInsight in the IDE?

 

Sorry if that's a stupid question 🙂 It may also be what Darian is interested in.

Share this post


Link to post

TestInsight does no magic in terms of "running tests" - it simply does the same as Run/Run without debugging. The client code then communicates via tcp/ip to the IDE to ask which tests are checked when you only want to run a limited selection and reports the results.

However in the few times that I had to run tests on mobile myself the experience is not as smooth as with windows, linux or osx that all support some UI less application that simply starts, runs tests and closes. So I usually had some minimal FMX UI that showed the tests and had a run button or something.

  • Thanks 1

Share this post


Link to post
On 10/9/2019 at 4:38 PM, Darian Miller said:

 

Any plans to support more platforms in Delphi?  I don't use FPC at all.

We don't use Delphi for other platforms.... but FPC...
There is no plan yet, due to how incompatible cross-platform was in Delphi. And even with ARC disabled, I am not sure it would be worth it.

 

There is a very small test framework in our Cross-Platform client units.

See https://github.com/synopse/mORMot/blob/master/CrossPlatform/SynCrossPlatformTests.pas

It is very lightweight, and should work on all platforms...

  • Thanks 1

Share this post


Link to post

Just a side note: I personally find very useful using CheckEqual methods instead of plain Check as they print both values in case of error which helps to find a concrete test that fails.

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

×