Unit Tests Framework

Discuss ZX Spectrum Next Games, Tools and more.
User avatar
Posts: 109
Joined: Sun Jul 09, 2017 5:56 am

Unit Tests Framework

Postby Maziac » Sun Aug 04, 2019 3:14 pm


I would like to inform you about the new update to my vscode debug extension for ZX Spectrum and ZX Next.

The v0.9 introduces a Unit Test Framework to test your assembler sources/binaries.
It is the first UT framework for assembler code. At least to my knowledge :-)
This is a bit strange because unit testing is extremely helpful especially for assembler code.
You can now easily refactor your code, improve performance etc. and check with your unit test that your sub routine is still working afterwards.

An additional feature is 'code coverage'. All lines executed during unit testing are highlighted in green.
I.e. you can easily spot the uncovered areas of your code and refine your unit tests.

For this to work you need:
- vscode
- the "Z80-Debugger" extension v0.9.1, https://github.com/maziac/z80-debug
- ZEsarUX v8.0
- and an assembler that supports macros. (recommended is the sjasmplus assembler)

Optionally you can also install:
- "Z80 Unit Tests" extension, https://github.com/maziac/z80-unit-tests: a graphical test explorer for vscode
- "ASM Code Lens" extension, https://github.com/maziac/asm-code-lens: for syntax highlighting and extended code navigation features

All extensions can be installed directly from the vscode market place.

Here are a few screens
Bildschirmfoto 2019-08-04 um 13.29.35.jpg
Test Explorer
Bildschirmfoto 2019-08-04 um 13.29.35.jpg (55.43 KiB) Viewed 1015 times
Bildschirmfoto 2019-08-04 um 13.23.17.jpg
Debug a unit test
Bildschirmfoto 2019-08-04 um 13.23.17.jpg (319.27 KiB) Viewed 1015 times
Bildschirmfoto 2019-08-04 um 13.22.28.jpg
Bildschirmfoto 2019-08-04 um 13.22.28.jpg (215.36 KiB) Viewed 1015 times
It all is cross platform. I.e. it is available on Windows, Linux and Mac.

A description how to setup an assembler project for unit testing can be found here:
https://github.com/maziac/z80-debug/bl ... tTests.md

If you would like to test it right away here is a sample Z80 assembler program that includes a few unit tests:


Please let me know what you think. Any feedback is appreciated and, of course, also bug reports.

Many thanks to Cesar especially for providing help to get the code coverage information from ZEsarUX.

For the next release I plan to change the version number to 1.0 and to add a reverse debug feature to complete the debugger.

Posts: 221
Joined: Mon Jul 16, 2018 7:11 pm

Re: Unit Tests Framework

Postby Ped7g » Sun Aug 04, 2019 7:31 pm

Absolutely amazing... so much, that I am even considering touching VSCode (so far my hate is stronger, but you are tempting me a lot, this stuff looks precisely down my alley).

Coincidently the sjasmplus itself is nearing 90% coverage ... :D https://coveralls.io/github/z00m128/sjasmplus

I'm sort of trying to finish the v1.x branch, with the next v1.14.0 being probably one of last v1.x releases, and move onto v2.x work, which will have somewhat different defaults in syntax and features, so some older sources will require slight editing to be working again ... but the v2.x is probably months away. Still you can let me know (update/create issues) in case you have further needs to support this project (particularly glaring bugs should be fixed even in v1.x version). For v2.x I will revisit those ideas and think about even more major changes.

I'm even considering trying to extend your work to Kate/KDevelop, but I'm afraid KDevelop itself would need year or two of my attention first to get it into some basic shape, before diving into major extensions of it (I'm using it for sjasmplus project, and while I would rate it "good enough", it's nowhere near the level of excellence of Android Studio, except the performance of course ... my experience with VS is now almost 20y outdated, so I will not even try to compare with VSCode). Hmm... I need to clone myself ... :D

Anyway, I really like your work done on this, and in case you have some serious issue with sj, ping me on github, I will give it priority.

User avatar
Posts: 231
Joined: Mon May 29, 2017 8:14 pm

Re: Unit Tests Framework

Postby chernandezba » Sun Aug 04, 2019 9:43 pm

Maziac wrote:
Sun Aug 04, 2019 3:14 pm

Many thanks to Cesar especially for providing help to get the code coverage information from ZEsarUX.

You’re welcome! Thanks to you for creating this external debugger using the ZEsarUX Remote Command Protocol. This is a great feature to encourage more people to use ZEsarUX :D

ZX Second-Emulator And Released for UniX

User avatar
Posts: 41
Joined: Tue May 30, 2017 8:37 pm

Re: Unit Tests Framework

Postby MrKWatkins » Sun Aug 04, 2019 11:23 pm

Awesome work! Well done.

User avatar
Posts: 278
Joined: Tue May 30, 2017 7:43 pm

Re: Unit Tests Framework

Postby Timbucus » Wed Aug 07, 2019 5:07 pm

This is a really amazing effort. When I get more time I will install vscode etc as an alternate toolchain and give it a go.
I'm Infinite Imaginations when not in work... PAWS for thought.

Who is online

Users browsing this forum: No registered users and 1 guest