Bob's remarks yesterday about unit testing had me look at Leo's unit 
testing framework with new eyes. 

#1467 <https://github.com/leo-editor/leo-editor/issues/1467> suggest using 
traditional unit tests everywhere, or maybe almost everywhere. Imo, this 
will be a significant improvement.  I'll use a script to do the conversion, 
so it shouldn't be a major project.

*Benefits of traditional unit tests*

Yesterday I converted (by hand) the @test nodes for leoAst.py in 
unitTest.leo to several Test classes within leoAst.py itself. There were no 
significant problems. Instead, I saw more and more advantages to 
traditional test classes and functions:

- Using classes and functions allows the test code to reside within the 
file being tested. Such code can be used by people who have not installed 
Leo.

- Common code can reside in, say, a BaseTest class. With @test nodes, such 
common code requires the ugly @common-code hack.

- Tests can be grouped by putting them in distinct Test classes, which will 
typically be subclasses of BaseTest.  The unittest module can run all tests 
within a module, or within a specific test class, or even a single test 
function:

python -m unittest test_module1 test_module2python -m unittest 
test_module.TestClasspython -m unittest test_module.TestClass.test_method

  
Such commands commands can be run within Leo.  For example, I used the 
following @button node yesterday:

import os
g.cls()
leo_editor_dir = g.os_path_finalize_join(g.app.loadDir, '..', '..')
os.chdir(leo_editor_dir)
commands = r'python -m unittest leo.core.leoAst.TestTOG'
g.execute_shell_commands(commands, trace=False)

*Grouping tests*

The big advantage (or so I thought) to @test nodes was that it is easy to 
run individual tests or group of tests.  But this advantage is an 
illusion!  Using clones, it is easy to run any desired group of test 
functions:

- Create a RecentTests test class.

- Use clones to add test functions to that class.

- Run the script in an @command run-recent-tests node, similar to that 
shown above.

*Summary*

@test nodes aren't nearly as useful as I thought they were. Traditional 
unit tests have many advantages over @test nodes.

Traditional unit tests play well with Leo. @command/button node can run 
groups of tests. Clones can be used to add test functions to test classes.

The new test classes will simplify Test Driven Development of Leo itself.

I'll use scripts to convert tests in unitTest.leo to test classes in Leo's 
core modules. unitTest.leo and (maybe) leoTest.py will likely be retired.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/9c1089c5-53bd-4ce8-b81b-a299813c2946%40googlegroups.com.

Reply via email to