1. Homepage
  2. Programming
  3. IN3329 Software Testing Assignment 1: Design testing strategies and write unit tests

IN3329 Software Testing Assignment 1: Design testing strategies and write unit tests

Engage in a Conversation
IN3329Software TestingJavaTest strategyUnit testMock-based Test

IN3329 Software Testing Assignment1 Guideline CourseNana.COM

Due Date: 24:00 09th Apr Marking Scheme for Assignment 1.Code Correctness 2.Coding Style(well-formatted, well commented) 3.Explanation CourseNana.COM

Please use markdown to write your report, it will save you tons of time. Tutorial: https://markdown.com.cn/ DO NO T PLAGRISM! CourseNana.COM

Specification A well submitted answer should contain the following content: CourseNana.COM

  1. The partition strategies , or a testing plan better be in the comment before the testing code.
  2. Code
  3. Explanation of the testing result(program result). Sample Answer would be like: Code with testing strategies:(Typescript form): describe("multiplication", function() { /*
    • Testing strategy
    • cover the cartesian product of these partitions:
    • partition on a: positive, negative, 0
    • partition on b: positive, negative, 0
    • partition on a: 1, !=1
    • partition on b: 1, !=1
    • partition on a: small (fits in a TypeScript number), or large (doesn't fit)
    • partition on b: small, large
    • cover the subdomains of these partitions:
    • partition on signs of a and b:
    • both positive
    • both negative
    • different signs
    • one or both are 0 / it("covers a = 1, b != 1, a and b have same sign", function() { assert.strictEqual(BigInt(1) BigInt(33), BigInt(33)); }); it("covers a is positive, b is negative, "
      • "a fits in a number, b fits in a number, "
      • "a and b have different signs", function() { assert.strictEqual(BigInt(73) * BigInt(-2), BigInt(-146)); });

2 / 5 ... }); Explanation: The strategy covers almost all situations only in 6 test cases, all the testing cases have been passed.(if all passed) there is a fail because...(if one fails) CourseNana.COM

  1. Design testing strategies and write unit tests for the following 2 methods:(5 marks) public static String operationString(String a){ String b = a; b = a+"c"; // System.out.println(a+b); return a+b; CourseNana.COM

    } public static StringBuilder operationStringBuilder(StringBuilder a){ StringBuilder b = a; b = a.append("c"); // System.out.println(a.append(b)); return a.append(b); } Code with t esting strat egies: Explanation: CourseNana.COM

  2. Design test strategies for the following code:(5 marks) public static int sumAbsolute(List list) { // let's reuse sum(), because DRY, so first we take absolute values for (int i = 0; i < list.size(); ++i) { list.set(i, Math.abs(list.get(i))); } return sum(list); } /**
    • @return the sum of the numbers in the list */ public static int sum(List list) { int sum = 0; for (int x : list) { sum += x; } return sum; }

Code with testing strategies: Explanation: CourseNana.COM

  1. Please write an algorithm for Hailstone Sequence:(10 marks) Set an initial n as 3, then print the Hailstone Sequence Receive an integer as the input Print the whole hailstone array. the expected function should be like this: output: 3,10,5,16,8,4,2,1 Code with comment: 4.(I) Please Encapsulate the Hailstone calculation process into a method:(10 marks) The Hailstone Method should function like this Input: an integer n > 0 Return: A corresponding Hailstone Sequence with any length. Code with testing strategies: Explanation: 4.(II) Write a test for the Hailstone Method:(10 marks) Code with testing strategies: Explanation:
  2. Answer some questions about Exception (20 marks) 5.1 Will the following code thr ow an ex ception or err or when y ou use it ?(5 marks) try {

} finally { CourseNana.COM

} Answ er: 5.2 If y ou use the following cat ch block , what kinds o f exception will it cat ch? What is wr ong with using the following block?(5 marks): catch (Exception e) { CourseNana.COM

} Answ er: 5.3 T ry to find the bugs inside the following code and explain why it is wr on, then mak e a judgement on whether it can be compiled(10 marks): try { } catch (Exception e) { CourseNana.COM

} catch (ArithmeticException a) { CourseNana.COM

} Answ er: CourseNana.COM

  1. Exercise: Modify the following method, make it throw suitable exception like FileNotFoundException....etc(10 marks) public static void cat(File file) { RandomAccessFile input = null; String line = null; try { input = new RandomAccessFile(file, "r"); while ((line = input.readLine()) != null) { System.out.println(line); } return; } finally { if (input != null) { input.close(); } } }

7.Please follow the Mock routine to design a Mock-based Test.(10 marks) Object discr iption: We want to take an order object and fill it from a warehouse object. The order is very simple, with only one product and a quantity. The warehouse holds inventories of different products. When we ask an order to fill itself from a warehouse there are two possible responses. If there's enough product in the warehouse to fill the order, the order becomes filled and the warehouse's amount of the product is reduced by the appropriate amount. If there isn't enough product in the warehouse then the order isn't filled and nothing happens in the warehouse. The stub code is like the following: CourseNana.COM

Note, Coding in Mock -based librar y(Mockit o, JMock , EasyMock) is not r equir ed, a w ell designed Mock logic is ev aluat ed(that is, y ou can get 10 marks if y our design is gr eat.) public class OrderStateTester extends TestCase { private static String TALISKER = "Talisker"; private static String HIGHLAND_PARK = "Highland Park"; private Warehouse warehouse = new WarehouseImpl(); protected void setUp() throws Exception { warehouse.add(TALISKER, 50); warehouse.add(HIGHLAND_PARK, 25); } public void testOrderIsFilledIfEnoughInWarehouse() { Order order = new Order(TALISKER, 50); order.fill(warehouse); assertTrue(order.isFilled()); assertEquals(0, warehouse.getInventory(TALISKER)); } public void testOrderDoesNotRemoveIfNotEnough() { Order order = new Order(TALISKER, 51); order.fill(warehouse); assertFalse(order.isFilled()); assertEquals(50, warehouse.getInventory(TALISKER)); } Explanation: CourseNana.COM

8.Write a Multiply method which can(20 marks) calculat e int eger s from -2^Int eger.MAX_V ALUE(ex clusiv e) to +2^Int eger.MAX_V ALUE. and then design a suitable t est strat egy and implement it in JUnit. ** Code with testing strategies: CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
IN3329代写,Software Testing代写,Java代写,Test strategy代写,Unit test代写,Mock-based Test代写,IN3329代编,Software Testing代编,Java代编,Test strategy代编,Unit test代编,Mock-based Test代编,IN3329代考,Software Testing代考,Java代考,Test strategy代考,Unit test代考,Mock-based Test代考,IN3329help,Software Testinghelp,Javahelp,Test strategyhelp,Unit testhelp,Mock-based Testhelp,IN3329作业代写,Software Testing作业代写,Java作业代写,Test strategy作业代写,Unit test作业代写,Mock-based Test作业代写,IN3329编程代写,Software Testing编程代写,Java编程代写,Test strategy编程代写,Unit test编程代写,Mock-based Test编程代写,IN3329programming help,Software Testingprogramming help,Javaprogramming help,Test strategyprogramming help,Unit testprogramming help,Mock-based Testprogramming help,IN3329assignment help,Software Testingassignment help,Javaassignment help,Test strategyassignment help,Unit testassignment help,Mock-based Testassignment help,IN3329solution,Software Testingsolution,Javasolution,Test strategysolution,Unit testsolution,Mock-based Testsolution,