Unit tests and clean shutdown

I came across this while adding to tests for Chimera.

Summary: make sure ‘teardown’ actions are in an AfterMethod (or AfterClass) annotated method, not in the test method.

In the ‘happy path’ (all tests pass), the test finishes by calling


which does a force close of the Jalview viewer and Chimera - as wanted.

But if a test assertion fails before that is reached, then it is not executed, and instead we hit the teardown, in this case:



which results in a call to


which puts up a user dialogue “Do you want to close Chimera” - just what we wanted to avoid while unit testing.

Move closeViewer(true) into an AfterMethod teardown instead.
That ensures it runs even if the test fails.
The TestNG equivalent of a finally block OutlookEmoji-😊.png.

Probably stating the obvious, but something to look out for when facing those annoying dialogues in tests.


The University of Dundee is a registered Scottish Charity, No: SC015096


Mungo Carstairs
Jalview Computational Scientist
The Barton Group
Division of Computational Biology
School of Life Sciences
University of Dundee, Dundee, Scotland, UK.