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.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
LtMandella
Posts: 61
Last visit: Mon May 07, 2018 4:03 pm

Design of pstudio winforms apps re. pester

Post 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
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Design of pstudio winforms apps re. pester

Post by davidc »

I moved this topic to the PowerShell GUIs forum so that other can respond.
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Design of pstudio winforms apps re. pester

Post by jvierra »

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
Last visit: Mon May 07, 2018 4:03 pm

Re: Design of pstudio winforms apps re. pester

Post by LtMandella »

thanks JV!

[[Eventually Pester may be integrated with PSS...maybe.]]
That would be _awesome_!!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Design of pstudio winforms apps re. pester

Post 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

User avatar
LtMandella
Posts: 61
Last visit: Mon May 07, 2018 4:03 pm

Re: Design of pstudio winforms apps re. pester

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Design of pstudio winforms apps re. pester

Post 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.
User avatar
LtMandella
Posts: 61
Last visit: Mon May 07, 2018 4:03 pm

Re: Design of pstudio winforms apps re. pester

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Design of pstudio winforms apps re. pester

Post 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.
This topic is 6 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked