Design of pstudio winforms apps re. pester

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.
Post Reply
User avatar
LtMandella
Posts: 61
Joined: Fri Feb 12, 2016 5:32 pm

Design of pstudio winforms apps re. pester

Post by LtMandella » Mon Nov 13, 2017 12:16 pm

Powershell Studio 5.4.136

Hi Folks,
Has anyone had any success designing Pshell studio winform apps and using pester for testing?

Pshell studio has been great for us for implementing some LOB CRUD apps that would otherwise have taken much more work to implement in C#. We would like to integrate use of pester for unit testing into our dev process but it just seems so incredibly awkward to do that with event driven programming paradigm of winform api.

Anyone have any experience they can share about how to do that effectively? Maybe pull as much as possible of the business logic out of the form ps1 into modules or libraries, pass data objects in and out as params, and use pester on those external libraries?

thanks,
LT

User avatar
davidc
Posts: 4954
Joined: Thu Aug 18, 2011 4:56 am

Re: Design of pstudio winforms apps re. pester

Post by davidc » Mon Nov 13, 2017 12:38 pm

I moved this topic to the PowerShell GUIs forum so that other can respond.
David
SAPIEN Technologies, Inc.

User avatar
jvierra
Posts: 11497
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Design of pstudio winforms apps re. pester

Post by jvierra » Mon Nov 13, 2017 12:45 pm

See these blog posts for some pointers.

https://www.sapien.com/blog/?s=pester

Eventually Pester may be integrated with PSS...maybe.

User avatar
LtMandella
Posts: 61
Joined: Fri Feb 12, 2016 5:32 pm

Re: Design of pstudio winforms apps re. pester

Post by LtMandella » Mon Nov 13, 2017 4:10 pm

thanks JV!

[[Eventually Pester may be integrated with PSS...maybe.]]
That would be _awesome_!!

User avatar
jvierra
Posts: 11497
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Design of pstudio winforms apps re. pester

Post by jvierra » Mon Nov 13, 2017 4:17 pm

LtMandella wrote:
Mon Nov 13, 2017 4:10 pm
thanks JV!

[[Eventually Pester may be integrated with PSS...maybe.]]
That would be _awesome_!!
Don't quote me on that. It is just an assumption that, if it is possible, it would be useful. For now use the Pester CmdLets.

Also do this:

Code: Select all

PS D:\scripts> find-module *pester*

Version    Name                                Repository
-------    ----                                ----------
4.0.8      Pester                              PSGallery
1.5.1      Format-Pester                       PSGallery
0.3.1      PesterMatchArray                    PSGallery
0.0.6      PesterHelpers                       PSGallery
0.3.0      PesterMatchHashtable                PSGallery


User avatar
LtMandella
Posts: 61
Joined: Fri Feb 12, 2016 5:32 pm

Re: Design of pstudio winforms apps re. pester

Post by LtMandella » Tue Nov 14, 2017 5:26 pm

thank you again!

Does seem like I will need to move much of the the logic in the winform event related logic into functions in separate file if I want to unit test using pester.

Then just . source the function file so the winform event handlers can reference the appropriate logic in the functions.

Of course that is still better than what I am doing now, which is just running the complete app for testing, and not really unit testing at all.

User avatar
jvierra
Posts: 11497
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Design of pstudio winforms apps re. pester

Post by jvierra » Tue Nov 14, 2017 5:38 pm

An event is a function. It is an anonymous function. In PowerShell a function is really a named scriptblock. An event can take a function pointer (delegate) and it can be named or anonymous.

Just tell Pester to test eh function.

User avatar
LtMandella
Posts: 61
Joined: Fri Feb 12, 2016 5:32 pm

Re: Design of pstudio winforms apps re. pester

Post by LtMandella » Wed Nov 15, 2017 11:05 am

Thanks, my first step will be to read through that blog and work through some pester tutorials.

The goal is to be able execute an external test script that would test functions in the separate winform application .ps1

And I would not want to have any test related artifacts residing in the application .ps1 even if it is just test related parameters.

User avatar
jvierra
Posts: 11497
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Design of pstudio winforms apps re. pester

Post by jvierra » Wed Nov 15, 2017 11:41 am

Pester is open source. You could modify it to extract and apply tests to scriptblocks. This would avoid unnecessary design changes to how a form is built.
The current version of Pester does not assume event driven issues so it may not work when the functions are called from a form as the variables I a function can be changed by another event under certain circumstances and pester may not assume this.

Post Reply