Note that there are some explanatory texts on larger screens.

plurals
  1. POAcceptance testing a legacy code
    primarykey
    data
    text
    <p>I'm following a course in agile practices and I have a homework. During the course, I've been taught on how to use FIT for automated acceptance tests. From what I can see, FIT seems to be dying and I'm no longer sure that it is the technology I want to use for my homework. Anyway...</p> <p>I have legacy system to test and everything is badly designed/coded. Of course there are no tests, and I'm not allowed to refactor or change functionality before writing any acceptance test.</p> <p>For the sake of simplicity, let's say the system is a shop receipt system that prints the products list (with prices) and the total cost to the standard output stream. Something like this:</p> <pre><code>public class ReceiptSystem { List&lt;Product&gt; boughtProducts = new ArrayList&lt;Product&gt;(); public void buyProduct(Product p) { boughtProducts.add(p); } public void printReceipt() { List&lt;ReceiptLine&gt; receipt = new ArrayList&lt;ReceiptLine&gt;(); int total = 0; int price; for(List&lt;Product&gt; boughtProducts : boughtProduct) { price = SomeThirdPartyClass.calculatePrice(boughtProduct.getBarcode()); System.out.println(boughtProduct + ": " + price); total += price; } System.out.println("TOTAL: " + total); } } </code></pre> <p>The problem is that the prices are calculated by a third party system with an external library, so I don't know them and I find it difficult (if not impossible) to write the acceptance test using FIT. In a normal case I would do something like:</p> <p>Shopping list (input):</p> <pre><code> ------------------- | product's barcode | ------------------- | 111111111 | ------------------- | 123456789 | ------------------- | 987654321 | ------------------- | 999999999 | ------------------- </code></pre> <p>Receipt (expected output):</p> <pre><code> ------------------ | receipt | ------------------ | 111111111: 1.99 | ------------------ | 123456789: 2.99 | ------------------ | 987654321: 3.99 | ------------------ | 999999999: 4.99 | ------------------ | TOTAL: 13.96 | ------------------ </code></pre> <p>But how can I achieve this without knowing the prices? What's the best strategy to adopt? Is there any other framework to achieve this?</p> <p>Thank you.</p> <p><strong>Update:</strong> The <code>SomeThirdPartyClass</code> is <code>final</code>, trying to mock it or to write a Proxy class for it will give the following error:</p> <blockquote> <p>Cannot subclass final class class SomeThirdPartyClass</p> </blockquote> <p>Furthermore, it's immutable and the public constructor has no arguments. Seems like the teacher made it on purpose....</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload