DEV Community

victor forissier
victor forissier

Posted on

AI-Tests Quest

I tried writing the outline of this article with ChatGPT. I asked it to be casual, but it went crazy into this fantasy mode. It was quite funny so I kept it mostly intact. xD.
– Victor (the writer)

Welcome, fellow engineers, to the magical land of ai-tests, a powerful tool conjured up by our friend Lancelot, designed to create test boilerplate code from your files. Though it may not create the perfect dragon-slaying sword every time, it does pretty well and can certainly save you from wrestling with the beast of initial test creation. If you'd like to get a feel for its magic, head on over to the repository here.

Fetching Your PolyFact Token

Before embarking on your journey, you'll need to obtain a mystical object - the PolyFact token. PolyFact is a magical API witch, with powers and spells unbeknownst to humankind. It is the key to generating AI responses in the ai-tests tool. Like all quests, obtaining this key involves a few steps:

  1. Navigate to the PolyFact Dashboard.
  2. Connect with your GitHub account.
  3. Once you've connected, copy your newly created token.

After securing your token, you'll need to embed it into your environment. We just use a simple export command for this:

export POLYFACT_TOKEN=<your_polyfact_token>
Enter fullscreen mode Exit fullscreen mode

Now you're all set!

Summoning the AI-Tests

Ready to summon the magic? Simply provide your file path to the ai-tests command. Here's how you do it:

$ npx ai-tests <input_file>
Enter fullscreen mode Exit fullscreen mode

And voila! Just like that, you'll have a batch of unit tests in the language corresponding to your input file. Now you're free to modify, add to, or otherwise adjust these tests as you see fit.

A Few Words of Caution

Though it's quite a handy tool, it's important to remember that ai-tests isn't a silver bullet. Like any tool, it's all about using it in the right context and for the right job. The generated tests can range from nearly perfect to needing a bit of refinement, but either way, they're a solid starting point.

Be aware of one limitation: the tool is sensitive to file size. If a file is too large, it'll generate multiple tests and concatenate them. Depending on the language, this may not always produce syntactically valid test files.

How to Lend a Hand

Oh, by the way, if you're interested in contributing or have some fantastic ideas to make this tool even better, Lancelot is always open to suggestions and improvements. Feel free to create a pull request or open an issue on the GitHub repository here. Let's make ai-tests the best it can be together!

And that's it! Enjoy your adventure with ai-tests. Remember, the goal here isn't to create perfect tests every time, but to give you a headstart on your testing journey.

Your friend,
Victor the Witch

Top comments (0)