mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2025-12-08 07:42:33 +01:00
Version 6.5 features and name change to AutoTest
Author:halw Date:2010-01-19T20:22:25.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@400 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
[[Property:title|Using extracted tests]]
|
||||
[[Property:weight|5]]
|
||||
[[Property:uuid|bebd4f28-9818-80f0-a69a-e9ce867723f4]]
|
||||
|
||||
==About extracted tests==
|
||||
|
||||
At any time that you are running a system in EiffelStudio debugger and your system is paused, you can ask the Eiffel Testing Framework to extract a new test class and test from the current executable context. Most often you would use this capability in the case in which you experienced an unexpected failure or exception in one of your routines. It is possible, though, to extract at any point at which the system is paused.
|
||||
At any time that you are running a system in EiffelStudio debugger and your system is paused, you can ask AutoTest to extract a new test class and test from the current executable context. Most often you would use this capability in the case in which you experienced an unexpected failure or exception in one of your routines. It is possible, though, to extract at any point at which the system is paused.
|
||||
|
||||
The value of extracted tests is that they provide a kind of a snapshot in testing form that will reproduce the unexpected failure. An extracted test attempts to reproduce the context in which the offending routine executed. So, extracted tests supplement your manual tests. They serve to cover situations which you just may not have written manual tests to cover.
|
||||
|
||||
@@ -13,7 +12,7 @@ Extracted tests are intended to supplement the suite of manual tests that you ha
|
||||
|
||||
==Creating an extracted test==
|
||||
|
||||
Let's use the same test system we used for manual tests to demonstrate the creation of an extracted test. The example will be slightly lame because it will find a problem that certainly we would already have discovered had we written a comprehensive set of manual tests against the <code>BANK_ACCOUNT</code> class. Still, the simplicity should help keep things clear.
|
||||
Let's use the same test system we used for manual tests to demonstrate the creation of an extracted test. The example will be slightly contrived because it will find a problem that certainly we would already have discovered had we written a comprehensive set of manual tests against the <code>BANK_ACCOUNT</code> class. Still, the simplicity should help keep things clear.
|
||||
|
||||
If you remember, the root class for the example application contained no instructions, just a root procedure with no instructions and a declaration <code>my_account</code> of type <code>BANK_ACCOUNT</code>:
|
||||
|
||||
@@ -44,13 +43,13 @@ Now, let's add some code into the <code>make</code> procedure that will make use
|
||||
If we run the application from EiffelStudio, we see that it stops when it incurs a postcondition violation in <code>{BANK_ACCOUNT}.withdraw</code>:
|
||||
|
||||
|
||||
[[Image:Testing Framework extracted 01]]
|
||||
[[Image:AutoTest extracted 01]]
|
||||
|
||||
|
||||
When we look at the feature pane, it's pretty easy to see where the problem is:
|
||||
|
||||
|
||||
[[Image:Testing Framework extracted 02]]
|
||||
[[Image:AutoTest extracted 02]]
|
||||
|
||||
|
||||
There is an error in the specification for <code>withdraw</code>. In the postcondition tagged <code>withdrawn</code>, the plus sign should have been a minus sign. Therefore, the assertion should read like this:
|
||||
@@ -59,28 +58,32 @@ There is an error in the specification for <code>withdraw</code>. In the postcon
|
||||
withdrawn: balance = old balance - an_amount
|
||||
</code>
|
||||
|
||||
Certainly we will fix this, but the Eiffel Testing Framework gives us the opportunity to extract a test based on this particular failure. So, let's do that.
|
||||
Certainly we will fix this, but AutoTest gives us the opportunity to extract a test based on this particular failure. So, let's do that.
|
||||
|
||||
So, we go to the Eiffel Testing Framework interface and click the ''Create new tests'' button to request the ''New Eiffel Test Wizard''. Because we are paused in the debugger, the test wizard appears with the '''Extract tests from running application''' radio button already checked:.
|
||||
So, we go to the AutoTest interface and click the ''Create new tests'' button to request the ''New Eiffel Test Wizard''. Because we are paused in the debugger, the test wizard appears with the '''Extract tests''' radio button already checked:
|
||||
|
||||
|
||||
[[Image:AutoTest new test wizard 01E 01]]
|
||||
|
||||
|
||||
When we click next, we are presented with the same ''New test class'' pane that we saw with manual tests. We can give the test class a name. <code>TEST_BANK_ACCOUNT_EXTRACTED_WITHDRAW_01</code> should be fairly descriptive. And we'll select the '''tests''' cluster.
|
||||
|
||||
When we click next, we are presented with a wizard pane that shows a depiction of the current call stack and asks us for which feature(s) on the stack we want to create the test:
|
||||
|
||||
[[Image:New test wizard screen 03E 01]]
|
||||
|
||||
[[Image:AutoTest new test wizard 03E 01]]
|
||||
|
||||
|
||||
The choice for <code>withdraw</code> is the selection we want, so we just click next. The Testing Framework creates the new test and returns us to the debugger, where our system is still on hold. We can stop execution and compile to include the new test.
|
||||
The choice for <code>withdraw</code> is the selection we want, so we just click next. AutoTest creates the new test and returns us to the debugger, where our system is still on hold. We can stop execution and compile to include the new test.
|
||||
|
||||
Now we see the new test class and test in the Testing Framework's interface windows.
|
||||
Now we see the new test class and test in AutoTest's interface windows.
|
||||
|
||||
|
||||
==Run the tests, fix a problem, run the tests==
|
||||
|
||||
We run our tests and we see that the test on <code>withdraw</code> is still failing:
|
||||
|
||||
[[Image:Testing Framework interface after run 04]]
|
||||
[[Image:AutoTest interface after run 04]]
|
||||
|
||||
If we fix the error in the postcondition in <code>withdraw</code> and re-execute the test, we find that it is successful.
|
||||
|
||||
@@ -132,7 +135,7 @@ One reason for the difference is that the class does not inherit directly from <
|
||||
|
||||
Notice that the call to the target routine <code>{BANK_ACCOUNT}.withdraw</code> is effected in the routine <code>test_withdraw</code> which passes an agent representing <code>{BANK_ACCOUNT}.withdraw</code> to the procedure <code>run_extracted_test</code>. The second argument to <code>run_extracted_test</code> is a <code>TUPLE</code> with the argument values which were used in the call to <code>withdraw</code> which caused the original assertion violation.
|
||||
|
||||
Another thing worth noting is the function <code>context</code>. This is how the Eiffel Testing Framework recreates the state of the instance of <code>BANK_ACCOUNT</code> at the time of the assertion violation.
|
||||
Another thing worth noting is the function <code>context</code>. This is how AutoTest recreates the state of the instance of <code>BANK_ACCOUNT</code> at the time of the assertion violation.
|
||||
|
||||
{{caution|The extracted test recreates the state at the point at which execution has halted. So, in the case of a postcondition or invariant violation, the values of the attributes will reflect any changes that have been made during the execution of the routine. (In the example, the value of balance is set to 400, rather than 500 as it would have been when routine <code>withdraw</code> began execution.) This could make a difference in whether the test extracted after an exception is a valid recreation of the original failure. One way of dealing with this, at least in simple cases like this, is to change the test class code to reflect the proper value. A safer way would be rather than extracting the test after the exception, restart the system and stop execution as it enters the failing routine, then extract the test at that point. }}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user