How does the testcase system work?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Phanes
Newbie
Posts: 4
Joined: Mon Feb 28, 2022 9:41 pm
Projects: Ruin Me
itch: phanes
Contact:

How does the testcase system work?

#1 Post by Phanes » Sun Jun 05, 2022 5:22 pm

Ren'Py seems to have an internal testing system that allows for automated testing of a game, making choices as it goes: https://github.com/renpy/renpy/blob/mas ... tcases.rpy

Recognizing that this presumably isn't robust enough to show up in the documentation: How is this meant to be run?

I'd love to be able to run various scenarios against new versions of my game, maybe comparing the game history to previous "blessed" versions. My dream is to be able to create an automated test suite for every choice in my game that exports a series of transcripts that I can diff against previous results to determine if there are unexpected changes, recognizing that this might not surface graphical issues.
Creator of queer erotic horror VN Ruin Me (NSFW).

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: How does the testcase system work?

#2 Post by zmook » Sun Jun 05, 2022 6:37 pm

Its official support status seems to be somewhere around "PyTom admits it exists, but doesn't answer questions about it."

viewtopic.php?t=42208
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Phanes
Newbie
Posts: 4
Joined: Mon Feb 28, 2022 9:41 pm
Projects: Ruin Me
itch: phanes
Contact:

Re: How does the testcase system work?

#3 Post by Phanes » Mon Jun 06, 2022 3:17 pm

My experimentation so far suggests one can run them like renpy.py "<project directory>" test <testcase name>, but if I do so it just yields some OpenGL errors, presumably because I'm just running it straight with a local Python 2 install without any packages set up. I'm not sure if there's a better way to run that -- I don't see a venv or anything in the renpy directory, just some bare lib folders -- but I'm guessing that it is supposed to start up a visible instance of the project to run the testcase. It seems to run the "default" testcase if you don't specify one, and I don't see any support for test suites or running all tests (but I might be missing something).

If anyone who comes across this thread has had success with running tests on their own project, I'd love some insight.
Creator of queer erotic horror VN Ruin Me (NSFW).

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How does the testcase system work?

#4 Post by PyTom » Wed Jun 08, 2022 11:35 pm

You should be able to run it with renpy.sh or renpy.exe and the rest of the command the same.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Phanes
Newbie
Posts: 4
Joined: Mon Feb 28, 2022 9:41 pm
Projects: Ruin Me
itch: phanes
Contact:

Re: How does the testcase system work?

#5 Post by Phanes » Fri Jun 10, 2022 1:31 pm

PyTom wrote:
Wed Jun 08, 2022 11:35 pm
You should be able to run it with renpy.sh or renpy.exe and the rest of the command the same.
Thank you so much! This let me figure out the rest. From what I can tell, the following is how to get testing working. It'll require some comfort with command lines and file systems, and experience with a test suite like Selenium will be handy for writing tests.

Create testcases anywhere in your project that represent a number of UX actions to take in your game. Follow https://github.com/renpy/renpy/blob/mas ... tcases.rpy as an example. One especially useful construction is click until "Certain Choice", which will click through dialogue until a choice appears with the given text, then click on that text. Also note how they use the test settings to cut transitions short.

You can have any number of testcases, and they can call each other. The testcase named default will be run if no name is specified on the command line.

To run the tests, you'll need a command line environment with the SDL_VIDEODRIVER variable set to something besides the default ("dummy") or it'll try to run the tests without opening a window and error out. For me, using Git Bash on Windows, this means I need to run export SDL_VIDEODRIVER=windows if I don't want to mess around with configuring variables elsewhere.

Finally, to run the tests, the command I've settled on is:

Code: Select all

renpy.exe --errors-in-editor <PROJECT DIR> test <TESTCASE NAME>
The --errors-in-editor isn't necessary, but will open a text file at the end if any errors occur.

When you finish your testcase, it will not automatically exit. The magic sequence that seems to reliably exit my game at the end, starting from an in-game dialogue situation, is:

Code: Select all

"History"
pause .5

"Main Menu"

"Yes"

"Quit"
Finally, something that I couldn't find in the existing testcases in the source is that you can include a line in your testcase like assert gender == GENDER_FEMALE and you'll get an error if the assertion isn't truthy.

If your test is successful, you'll see the window appear, run through the actions you've specified, and then close (if you manually exited as part of the test). If a text file with errors doesn't appear, you're golden!
Creator of queer erotic horror VN Ruin Me (NSFW).

Post Reply

Who is online

Users browsing this forum: No registered users