photog.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
A place for your photos and banter. Photog first is our motto Please refer to the site rules before posting.

Administered by:

Server stats:

265
active users

#unittests

0 posts0 participants0 posts today

Hey Mastodon, question for my #sysadmin and #DevOps types. Has anyone used #Pester and #PSScriptAnalyzer to set up unit testing for test driven development, particularly on (relatively) simple scripts like you might use for application detection, installation, and uninstallation from a system like #SCCM #Intune or #ManageEngine ?

Apologies for the buzzword bingo, but I’m trying to reach folks who may be following the hashtags, but not necessarily have a connection otherwise.

Continued thread

In a way it’s similar to the people who generate #unittests for the code they’ve just written.

Nothing against those who have this big chunk of untested legacy code and happily see that #AI gives them a good starting ground of test cases.

But like with commit messages, unit tests can answer that WHY question about your production code. Why do we need that strange if branch? Oooh because of that edge case occurring in a given use case, tested by this test case over there. That’s something you can’t derive from your production code.

In #TDD, your test cases give your production code a reason to exist. In that sense, you’d be much better off to have AI generate the production code for your tests.

One thing for my job I’m looking forward to about #AI: Refactoring large systems

Doing a refactoring that involves hundreds of classes and multiple changes of infrastructure has been a thing that can take weeks, even months.

However, if you have good test coverage, you can let an LLM can do the drudge work for you and just verify it did what it said it did.

TTD is a must anyway, if you use LLM’s for helping you werite code.
#programming #refactoring #unittests

UwU, I've just found out about `SystemState` in #Bevy :awesome:

docs.rs/bevy/latest/bevy/ecs/s

It basically allows you to circumvent (mutable) borrowing issues with `App` and `World` when you have exclusive `World` access.
As it turns out, this is especially useful in #UnitTests. 🧪 ✅

See next two toots for an example...

1/3

docs.rsSystemState in bevy::ecs::system - RustHolds on to persistent state required to drive `SystemParam` for a `System`.
Continued thread

Ah, turns out I was totally stupid! 🤦

I've forgotten to include the following Plugin:

TextPlugin

When testing in a separate crate with 0.14, I had included it, but not in my new 0.15 project. Stupid me!😖

Now layouts are correctly calculated in tests. :awesome:

I apologize to everyone for the confusion and especially to the #Bevy project for blaming them of something that was totally my oversight. 😳

So I just got a development release up for my WP-Tests-Strapon Composer package up on Github. (Not on Packagist yet as it's still under initial development.)

It is a replacement for the install-wp-tests.sh shell script that comes with some scaffolded WordPress plugins and should be easier to use and keep working.

It also does not depend on outdated things such as Subversion/SVN and uses PHP for most of its actions.

github.com/aldavigdis/wp-tests

GitHubGitHub - aldavigdis/wp-tests-strapon: Strap your WordPress PHPUnit tests library onto your WordPress plugin or theme with this handy Composer package.Strap your WordPress PHPUnit tests library onto your WordPress plugin or theme with this handy Composer package. - aldavigdis/wp-tests-strapon

And this is why #UnitTests and #TDD are awesome/necessary (even in #Rust/ #RustLang):

The original requirement:
figure out how many columns the _result_ of diffing two CSVs in #CsvDiff have.

Do you see the error-pattern?

It's
- when we have no diff
&&
- at least one CSV has headers

which makes sense, because I've implemented the feature in the diffing logic, but at that point header information is already lost (in some other thread).

Isn't that beautiful!?🥰

Sometimes in a unit test I parameterize a value for a specific key in a dict. For a string I might have None, an empty string, and a test string.

What if I wanted to test the *absence* of the key? Suppose the test is non-trivial and I don't want to create a separate test.

Well one technique is to create a sentinel object:

```
class Omit: pass
_OMIT = Omit()
```

In the test I add a conditional:

```
if value != _OMIT:
testdict["key"] = value
```