Page 1 of 1

Design of pstudio winforms apps re. pester

Posted: Mon Nov 13, 2017 11:16 am
by LtMandella
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

Re: Design of pstudio winforms apps re. pester

Posted: Mon Nov 13, 2017 11:38 am
by davidc
I moved this topic to the PowerShell GUIs forum so that other can respond.

Re: Design of pstudio winforms apps re. pester

Posted: Mon Nov 13, 2017 11:45 am
by jvierra
See these blog posts for some pointers.

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

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

Re: Design of pstudio winforms apps re. pester

Posted: Mon Nov 13, 2017 3:10 pm
by LtMandella
thanks JV!

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

Re: Design of pstudio winforms apps re. pester

Posted: Mon Nov 13, 2017 3:17 pm
by jvierra
LtMandella wrote: Mon Nov 13, 2017 3: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


Re: Design of pstudio winforms apps re. pester

Posted: Tue Nov 14, 2017 4:26 pm
by LtMandella
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.

Re: Design of pstudio winforms apps re. pester

Posted: Tue Nov 14, 2017 4:38 pm
by jvierra
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.

Re: Design of pstudio winforms apps re. pester

Posted: Wed Nov 15, 2017 10:05 am
by LtMandella
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.

Re: Design of pstudio winforms apps re. pester

Posted: Wed Nov 15, 2017 10:41 am
by jvierra
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.