📜 ⬆️ ⬇️

Based on GUIRunner

Part 1 .
Part 2 .
Part 3

Today I added a post about how we decided to write our GUIRunner for FireMonkey. In the comments to the post in one of the social networks, Alexei Timokhin drew my attention to another well-known testing framework, DUnitX.
I tried to find an alternative, use the console version, but Alexander was inexorable. When I went to the repository, I saw the ready GUIRunner for FireMonkey, completely wilted.

But.

After the first launch, my first message to Alexander was - "lol. There are no" ticks "." So the problem was solved not in vain. After a closer look, I got the impression that the person who wrote this form also partially looked at Original GUIRunner.
')
In general, I would be very happy about this gift a month ago, while the FireMonkey cones are not packed yet. Well, today I was just wondering how another programmer solved this problem.

A number of errors we made almost the same. In a post, I wrote about how we “bind” tests and branches and finally ended up with a sentence on refactoring using TDictionary. Let me remind you, as in the original:

l_Test.GUIObject := aNode.Items[l_Index]; ... l_TreeViewItem.Tag := FTests.Add(aTest); 

The developer DUnitX did about the same, though, he made a wrapper over the TTreeViewItem (in the future I will add to myself):

 type TTestNode = class(TTreeViewItem) strict private FFullName: String; FImage: TImage; public constructor Create(Owner: TComponent; Text: String; TestFullName: String); reintroduce; destructor Destroy; override; property FullName: String read FFullName; procedure SetResultType(resultType: TTestResultType); procedure Reload; end; 

And I connected each test with a branch by the name of the test.

 function TGUIXTestRunner.GetNode(FullName: String): TTreeViewItem; var i: Integer; begin Result := nil; i := 0; repeat begin if (TestTree.ItemByGlobalIndex(i) as TTestNode).FullName = FullName then Result := TestTree.ItemByGlobalIndex(i); Inc(i); end until Assigned(Result) or (i >= TestTree.GlobalCount); end; 

I was surprised by another:

  FFailedTests: TDictionary<String, ITestResult>; 

Guess why do we need a String key? That's right to get to the branch through it and report on its condition after the test result. As for me, they were too smart.

Special mention deserves the class TTreeNode. He keeps a “link” to the test and a picture that will change the state of the branch. Since the class is inherited from TreeViewItem, this code lives fine:

 var testNode : TTreeViewItem; ... testNode := CreateNode(TestTree, test.Name, test.Fixture.FullName + '.' + test.Name); ... function TGUIXTestRunner.CreateNode(Owner: TComponent; Text: String; TestFullName: String): TTreeViewItem; begin Result := TTestNode.Create(Owner, Text, TestFullName); end; ... constructor TTestNode.Create(Owner: TComponent; Text, TestFullName: String); begin inherited Create(Owner); Self.Text := Text; FFullName := TestFullName; FImage := TImage.Create(Owner); FImage.Parent := Self; {$IFDEF DELPHI_XE6_UP} FImage.Align := TAlignLayout.Right; {$ELSE} FImage.Align := TAlignLayout.alRight; {$ENDIF} FImage.Bitmap.Create(15, 15); FImage.Bitmap.Clear(TAlphaColorRec.Gray); FImage.SendToBack; end; 

Overall, DUnitX made a good impression on me. The framework seems much more solid than its older brother. The guys revised the interfaces and architecture and, I think, even improved them. All code is very neat. Comments more at times. I will look and compare.

Links


Delphi-Mocks repository . Required to compile the framework;
DUnitX repository.

Source: https://habr.com/ru/post/241377/


All Articles