Auto-generate unit tests in macro-like way
-
Recently I’ve been lamenting the dearth of proper unit tests in Notepad++, and I’ve been trying to think of good ways to implement them. I believe some unit testing framework should be included with Notepad++ itself, rather than as a plugin. I’m going to create an issue about this on the GitHub, but I wanted to post here as well.
The first solution that came to my mind was PythonScript, but that’s not really a good solution for development (which is exactly where you most need unit tests) because it’s a plugin and thus would need to be installed before a developer could run unit tests.
My current thought on how I’d like this implemented would be to create a new toolbar section where the user could create a new unit test through the following steps:
- the user clicks a button, and a messagebox pops up and tells the user to specify the starting text of their test file.
- a new file opens, the user enters their starting text
- the user clicks another button, and a new messagebox tells the user to perform some actions just as if they were recording a macro (probably just use the existing macro recorder to record actions)
- when the user is done, they click another button. A new messagebox pops up and tells the user to specify what the text of the file should look like after that transformation.
- A new file opens, and the user enters their desired result text.
- The user clicks another button, and some C++ code is generated that creates a new file with the start text, repeats the macro steps, and then calls some testing function that asserts the result of those macro steps is equal to the final text.
The reason I like this design is that it simplifies the process of creating a UI test, while still allowing the developer to customize the test afterwards by adding lines of code to the generated test function as desired.
I’m happy to work on creating this myself, but I’d like feedback on how useful and achievable this would be, or if they have better ideas of how to streamline unit testing. @Alan-Kilborn , I know you’ve been working on a macro disassembler, and it seems like your work there could potentially be relevant.
-
What benefit would someone using a language other than C++ get from this? Do you have something in mind how to test plugins that don’t change the text but provide additional functionality, like explorer plugin or nppexec …?
-
@Ekopalypse
The main reason I see for creating unit tests like this is that (a) a lot of people do use C++ to make plugins, so it could be beneficial in that way, and (b) this could make it easier to detect if a change to Notepad++ created some backwards-incompatible change to core macro-able features.But I’m glad to hear any feedback, even skeptical feedback. If nobody is interested in adding unit tests, or at least not in this way, I won’t bother trying to implement this.
-
Don’t get me wrong, I’m not against unit testing at all, but I don’t understand what you’re trying to accomplish, hence my questions.
How would you test something like Scintilla’s annotations or styles?
I assume that most plugins have non-npp related functions, i.e. non-macro writable, as their core functions, how do they use the unit tests? For example, the xml-tools plugin checks if the xml document is valid. How would I write a unit test for that? -
@Ekopalypse
I should clarify, I meant that this would be for unit testing Notepad++ itself.Plugins might be able to use it, but I primarily envision this as a better alternative to what seems to be the current standard method for fixing bugs in the core functionality, namely fix it, describe the method for reproducing it, and hope that it stays fixed.
-
If you can hack Perl, there’s Win32::Mechanize::NotepadPlusPlus.
-
@Mark-Olson said in Auto-generate unit tests in macro-like way:
I know you’ve been working on a macro disassembler, and it seems like your work there could potentially be relevant.
Work on the disassembler has halted for the moment as the xml format for shortcuts.xml (where macros are stored) is undergoing change for the upcoming N++ 8.5.3. Since the existing format was giving the disassembler “problems”, I want to wait and see what the new format does to it.
-
@rdipardo said in Auto-generate unit tests in macro-like way:
If you can hack Perl, there’s Win32::Mechanize::NotepadPlusPlus
Ooh, if someone other than me and @Michael-Vincent acknowledge its existence, I suppose I need to find the time to go update it for all the new messages and updates that have been added since Notepad++ v8.3.3
If @Mark-Olson cannot hack Perl, the same principles can be applied from other languages: although Don’s reason for the Messages were for Plugin Communication, any process – whether a plugin for Notepad++ or an external process like Perl script or a C executable or even something like AutoHotKey – can SendMessage to any Win32 window… so if you know how to search for Notepad++'s hWnd in your language of choice, and know how to use the SendMessage from win32-API in your language-of-choice, you too can remote-control Notepad++, even without a “plugin”.
(The next version of the User Manual’s Plugin Communication will actually emphasize that external processes like AHK can SendMessage to Notepad++.)