Skip to content

Commit 505edbe

Browse files
committed
continued with TDD article
1 parent efe341d commit 505edbe

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

_drafts/2015-01-01-automated-testing-maya-plugin-development.md

+36-2
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,49 @@ Another big goal was to require as little alt-tabbing as possible; having to swi
3232

3333
* Run Maya from Eclipse (more on that later);
3434
* Run tests from Eclipse;
35-
* Route all outputs to single console in IDE;
35+
* Route all outputs back to Eclipse;
36+
* Eliminate any need to switch to Maya window at all - be it reloading a plugin, setting some required options for debugging or inspecting a problem.
3637

3738
Ideally this would allow me to just sit in Eclipse and perform the whole development cycle in one tool.
3839

3940
## The setup in action
4041

42+
So this is where I am now. It's not really a one-click solution yet, but comfortable enough for me not to worry at this point.
4143

42-
*TODO: describe current setup in action*
44+
### Running tests
4345

46+
The typical development session would start with running the whole set of tests. First, let's fire up Maya, there's a shortcut in IDE prepared for that; Maya quietly starts in the background, gets configured with all sorts of specific options just for this project, and starts listening for test launches.
47+
48+
Then, I execute the whole test suite. After it completes, I get this:
49+
![Test result](/assets/maya-test/test-result.png)
50+
51+
The console on the left is test execution script, which is mostly just shows test summary. The console on the right is Maya: it shows both C++ `cout`s and Python `print`s, and for each test being performed, the separator is put so I can see where one test ends and another begins, if any troubleshooting is needed.
52+
53+
If any test fails, the output would similar to this, with a convenient hyperlink to exact place in the code, being another benefit of doing everything in one tool:
54+
![Test result](/assets/maya-test/test-result-fail.png)
55+
56+
### Getting all tests together
57+
58+
There's no obvious way of "run all tests that you find" from inside Maya, things like [Nose](http://pythontesting.net/framework/nose/nose-introduction/) don't quite work; my solution is to use a highly simplified version of Nose approach, by going through all of modules and finding any test class. I do it with a `testsAll.py` in root test package with this:
59+
60+
{% highlight python %}
61+
for root, dirds, files in os.walk(os.path.dirname(__file__)):
62+
root = root[len(packageRoot)+1:].replace(os.sep,".")
63+
64+
for f in files:
65+
if f in ["__init__.py","testsAll.py","testUtils.py","reloadPlugin.py"]:
66+
continue
67+
if f.endswith(".py"):
68+
module = __import__(root+"."+f[:-3],fromlist=[root])
69+
for _,c in inspect.getmembers(module, inspect.isclass):
70+
if isTestsClass(c):
71+
decorateTestMethods(c)
72+
globals()[c.__name__.replace(".","_")] = c
73+
{% endhighlight %}
74+
75+
Basically, after imported, `testsAll` module will have imported all tests classes that it finds in subpackages. `decorateTestMethods` adds some additional behaviour like printing test name in the log before each test.
76+
77+
Having this `testsAll` module means that I can use `unittest.TestLoader().loadTestsFromModule` to programmatically load all of my tests into one big suite and run it inside Maya, removing the need of command line tool for test discovery.
4478

4579

4680
## Base set of tools

assets/maya-test/test-result-fail.png

80.8 KB
Loading

assets/maya-test/test-result.png

163 KB
Loading

0 commit comments

Comments
 (0)