UNIVERSITY OF MALTA FACULTY OF ICT Department of Computer Science B.Sc. (Hons.) ICT – 3rd Year June 2012 Assessment Session CPS3222: Fundamentals of Software Testing 19th April 2012 Sample Paper Answer question one and any other two questions. If more than three questions are answered, only the first three questions in the booklet will be taken into account. The mark of this exam will contribute towards 50% of the final mark of CPS3222. Green Technologies Ltd is a startup company which produces software for the efficient use of energy and has been in operation for five years. Their flagship product, GreenHome Pro, uses input feeds from various sensors around a house and in turn monitors and controls the electricity usage of individual appliances in the home. For example, if the lights are on in a particular room but sensors in the room have not sensed movement for more than five minutes, the lights will be turned off. System behavior is controlled by a user-configurable usage profile. 1. [Compulsory] The company is planning to implement a web-based management console for GreenHome Pro and the product manager has provided a list of languages, operating systems and browsers which must be supported. These are listed in Table 1 and result in 250 possible language-OSbrowser combinations. Considering that the product requires the execution of approximately 500 test cases, resulting in a total of 125,000 tests, the technical manager has turned to you for help. a. Given the substantial combinatorial challenge involved with testing all Browser/OS/Language combinations, discuss different overall test case design strategies which you would use. What are the pros and cons of each? [5 marks] page 1 of 5 PTO # 1 2 3 4 5 6 7 8 9 10 Language English Spanish Italian French Cantonese Operating System Windows XP Windows Vista Windows 7 Mac OS X Linux Browsers Internet Explorer 7 Internet Explorer 8 Internet Explorer 9 Internet Explorer 10 Chrome Firefox 9 Firefox 10 Firefox 11 Safari Opera Table 1: The list of supported languages, operating systems and browsers as required by the product manager. b. The product manager has stated that he is willing to compromise for the first release of the product. The product can support (i) English and Italian languages, (ii) Windows 7 and Mac OS X in terms of operating systems and finally (iii) Firefox 11 and Chrome when it comes to browsers. Whilst this results in only 8 possible combinations, the fact that there are 500 test cases for each combination still leads to a staggering 4000 tests. Your manager wants to reduce this by half whilst maintaining a sufficient level of coverage. Produce a list of Browser/OS/Language combinations which you feel will provide adequate coverage. Explain how your choice of combinatorial test case design technique works and why you chose it for this particular case. [10 marks] As a developer on the GreenHome Pro product, you have been asked to implement and maintain a unit testing suite for the system. You look into this and find the following class: public class Controller() { public void AutoSetLights(Room room) { // Gain access to motion sensor page 2 of 5 PTO MovementSensor motionSensor = new MovementSensor(room); // Gain access to lights LightController lightController = new CeilingLightController(room); // Create clock instance Clock clock = new Clock(); /** * Lights are only permitted to be on at the following periods: * 1. Early morning 6:00am - 8:00am * 2. Late evening 7:00pm - 11:00pm * * If there is no recent movement in the room, * the light will be turned off. */ int currentHour = clock.getCurrentHour(); if (room.inhabitant().isChild() && currentHour >= 20) { //After 8pm, only night lights are used in the children’s rooms lightController = new NiteLightController(); } if ( (currentHour >= 6 && currentHour <= 8) || (currentHour >= 19 && currentHour <= 23)) { if (!motionSensor.recentMovement()) { lightController.switchOff(); } } } } c. One of the biggest challenges of unit testing is the isolation of the method under test. Why is this important and why is it difficult? Explain the concept of test doubles and discuss how the different page 3 of 5 PTO types of test doubles can help alleviate the isolation problem. [15 marks] d. The code in this sample suffers from testability issues. Write a testable version of the code given in the sample, explaining what testability issues you solved and what test pattern you applied to do so.[15 marks] e. Describe a number of test cases which you think sufficiently test this code. E.g. “I would run a test at 2pm and check that the light is turned of”. What technique(s) did you use to design your test cases? [5 marks] 2. [Optional] The software architect has asked you to recommend an integration test approach for this particular system. a. Discuss the four main levels of testing, identifying the scope of each type and who would typically be responsible for it. [5 marks] b. How would you relate regression testing to unit testing? Mention three types of errors which are typically found during integration testing [5 marks]. c. How would you categorise different integration testing strategies? Discuss and related four different approaches to integration testing whilst making sure to pick at least one strategy from each category you provide in the first part of this question. [10 marks] d. What integration testing strategy would you recommend for this particular product? Explain the rational behind your choice. [5 marks] 3. [Optional] Based on market research, the company has determined that their typical users tend to act in certain patterns on a daily basis. Your manager would like to take advantage of this knowledge and use it in the testing process by creating a user behaviour model and then using the model to generate and execute test cases against the system. A user’s behaviour is composed of a sequence of the following actions: page 4 of 5 PTO (a) Leave home (b) Enter home (c) Go to kitchen (d) Go to bedroom (e) Turn light on (f) Turn light off a. Discuss model-based testing in the context of this scenario and argue for (or against) its use as you deem fit. [5 marks]. b. Select a type of model to use in this scenario and create a model that depicts possible user behaviours. Briefly discuss and justify your approach and the model itself. You may assume that when someone leaves the house, they are gone long enough for the lights to have been automatically turned off. [10 marks] c. Discuss two approaches to model-based test-case generation. What are the pros and cons of each one and which would you recommend for this particular context? How would you measure the effectiveness of these approaches? [10 marks] 4. [Optional] Consider the code fragment for the method AutoSetLights(Room) from question 1. a. Constract a control flow graph for this code fragment. [7 marks] b. Referring to the code fragment, demonstrate how 100% statement coverage does not necessarily lead to 100% branch coverage. Also, demonstrate how a fault may still be introduced if you achieve 100% branch coverage. What coverage criteria can be used to preempt the latter problem and why? [4 marks] c. Construct a data flow model of the code fragment and identify all definition-use pairs. Also identify any paths which lead to a definition being killed. [8 marks] d. How is data flow analysis useful in testing? Define two data-flow based coverage criteria and identify one possible complication related to data-flow based adequacy criteria in general. [6 marks] page 5 of 5 end of paper