Find Content

Engineering Maintainable Android Apps Coursera Quiz Answers

Get All Weeks Engineering Maintainable Android Apps Coursera Quiz Answers

Engineering Maintainable Android Apps, which is a 4 week MOOC that shows by example various methods for engineering maintainable Android apps, including test-driven development methods and how to develop/run unit tests using JUnit and Robotium (or equivalent automated testing frameworks for Android), as well as how to successfully apply common Java/Android software patterns to improve the extensibility and clarity of Android apps.

Students will work on the appropriate automated unit quizzes, based on the material covered in the lecture videos. These lessons will demonstrate the benefits of good software engineering practices that are targeted at creating maintainable code for mobile apps.

There will be roughly 3-4 hours of student engagement time per week, including video lectures, and quizzes. The ordering of the modules within the course is designed to be flexible.

In particular, students can watch the videos in whatever order suits their experience and needs, e.g., they may want to watch the unit testing videos prior to the software pattern videos if they prefer to learn about unit testing first.

Enroll on Coursera

Week 1: Engineering Maintainable Android Apps Coursera Quiz Answers

Quiz 1: Testing I Quiz

Q1. Which of the following are reasons to write tests (select all that apply)?

  • to ensure that new functionality operates as expected
  • to make apps run faster by reducing binary sizes
  • to help make sure that changes to code do not break existing functionality
  • to measure how effective software developers are

Q2. When building a new app, which of the following are true (select all that apply)?

  • There is exactly one way to implement it.
  • Finding the right design may be an iterative process.
  • Measuring the impact of changes is critical.
  • There is exactly one way to design it.

Q3. What is a unit test (select all that apply)?

  • a test that isolates a specific component for evaluation
  • a test that isolates multiple components for evaluation
  • a measurement of test coverage
  • a test that measures performance
  • a test of a single user interface element

Q4. Which Java framework is used to write unit tests in Android (select all that apply)?

  • Retrofit
  • Apache Commons
  • JUnit
  • Dagger
  • Android

Q5. Why is it important for unit tests to run quickly (select all that apply)?

  • to ensure that user interface components are not slowed down
  • to minimize the time developers wait for feedback on their code changes
  • to avoid blocking the main thread in an Android app
  • to minimize the number of mistakes that developers make
  • to minimize the startup time of the Android emulator

Q6. Which of the following is a valid, although not useful, JUnit test (select all that apply)?

  • 123 public void test() { ensureTrue(true); }
  • 1234 @Unit public void test() throws Exception { assert(true == true); }
  • 1234 @Test public void ensureTrue() { assertEquals(true, true); }
  • 1234 @Unit public void ensureTrue() { assertEquals(true,true); }
  • 1234 @Testpublic void test() { ensure.that(true); }

Q7. Which of the following is not an appropriate way to setup the state for MyObject in the test below (select all that apply)?

  • 123456 private MyObject myObject = new MyObject();

@Test public void testInitialName() { assertEquals(“bob”, myObject.getName());}

  • 123456789101112 private MyObject myObject;

@Test public void testInitialName() { myObject = new MyObject(); assertEquals(“bob”, myObject.getName());}

@Test public void testInitialSize() {

  • 1234567891011 private MyObject myObject;

@Before public void setUp(){ myObject = new MyObject(); }

@Test public void testInitialName() { assertEquals(“bob”, myObject.getName());

  • 12345678910111213141516 private MyObject myObject;

@Before public void setUp(){ myObject = new MyObject ();}

@Test public void testInitialName() {assertEquals(“bob”, myObject.getName());

  • 1234567891011 private MyObject myObject = new MyObject();

@Test public void testInitialName() { assertEquals(“bob”, myObject.getName()); }

@Test public void testInitialSize() { assertEquals(10, myObject.getSize());

Q8. Assume that the MyObject.dangerous() function throws a checked exception. Which of the following are valid ways to write a test of MyObject (select all that apply).

  • 12345 @Unit public void someTest() throws Exception { MyObject obj = new MyObject(); assertEquals(false, obj.dangerous()); }
  • 1234567 @Test public void someTest() { MyObject obj = new MyObject(); try{ assertEquals(false, obj.dangerous()); }catch(Exception e){ e.printStackTrace(); } }
  • 12345 @Test public void someTest() throws Exception { MyObject obj = new MyObject(); assertEquals(false, obj.dangerous()); }
  • 12345 @Test public void someTest() { MyObject obj = new MyObject(); assertEquals(false, obj.dangerous()); }
  • 1234567 @Test public void someTest() {MyObject obj = new MyObject(); try{ assertEquals(false, obj.dangerous()); }catch(Exception e){} }

Q9. What are valid uses of code coverage metrics (select all that apply)?

  • to determine where more testing may be needed
  • to guarantee that an app is bug free
  • to evaluate the quality of a development team
  • to determine if an app has been tested sufficiently
  • techniques to help developers test faster

Q10. Which of the following are true about the test shown below (select all that apply):

12345678910111213

public class SomeTest {

private MyObject myObject = new MyObject();

@Test

public void testInitialName() {

assertEquals(“bob”,myObject.getName());

}

@Test

public void testInitialSize() {

  • The MyObject constructor will be called at least once for each @Test annotation in the class.
  • The MyObject constructor will be called a single time before testInitialName() is executed and not called before any of the other test methods.
  • The MyObject constructor will be called a single time before testInitialSize() is executed and not called before any of the other test methods.
  • The MyObject constructor will not be called and testInitialName will throw a null pointer exception.
  • The MyObject constructor will not be called and a @Before annotation is needed to provide a method to set the initial state of myObject.

Week 2: Engineering Maintainable Android Apps Coursera Quiz Answers

Quiz 2: Testing II Quiz

Q1. What is an Android Instrumentation Test (select all that apply)?

  • a performance test for an application to measure its memory usage.
  • a test that includes a code coverage calculation
  • a test that measures user interactions with the user interface
  • a performance test for an application to measure its CPU usage.
  • an integration test that includes the Android runtime libraries.

Q2. Which of the following are true of unit tests vs. integration tests (select all that apply)?

  • Integration tests isolate individual components while unit tests check the interactions of multiple components.
  • Unit tests are typically slower than integration tests.
  • The failure of a unit test often more directly points to the source of the failure than an integration test,
  • Unit tests isolate individual components while integration tests check the interactions of multiple components.
  • Integration tests are often slower than unit tests.

Q3. Which of the following creates a valid mock PostalCodeProvider that will return “37212” for the following call (select all that apply):

1 postalCodeProvider.getPostalCode(2.11, 3.09)

  • 12345678910111213

@RunWith(MockitoJUnitRunner.class)

public class GeoUtilsTest {

@Mock
private PostalCodeProvider postalCodeProvider;

@Before
public void setUp() {
    when(
      postalCodeProvider
  • 12345678910111213

@RunWith(MockitoJUnitRunner.class)

public class GeoUtilsTest {

@Mock
private PostalCodeProvider postalCodeProvider;

@Before
public void setUp() {
    when(
      postalCodeProvider
  • 12345678910111213

@RunWith(MockitoJUnitRunner.class)

public class GeoUtilsTest {

@Mock
private PostalCodeProvider postalCodeProvider;

@Before
public void setUp() {
   on(
      postalCodeProvider
  • 123456789101112131415

@RunWith(MockitoJUnitRunner.class)

public class GeoUtilsTest {

@Mock
private PostalCodeProvider postalCodeProvider;

@Before
public void setUp() {
    when(
      postalCodeProvider
  • 12345678910111213

@RunWith(MockitoJUnitRunner.class)

public class GeoUtilsTest {

@Mock
private PostalCodeProvider postalCodeProvider;

@Before
public void setUp() {
    when(
      postalCodeProvider

Q4. Which of the following are true (select all that apply)?

  • Mocks can only be used for interface implementations.
  • Mocks can only be used for Android components.
  • Mocks can be used to help make tests run faster by eliminating slow running components.
  • Mocks help to improve test coverage.
  • Mocks can be used to help isolate components for unit tests.

Q5. What will be the result of line 19 (select all that apply)?

12345678910111213141516171819202122

@RunWith(MockitoJUnitRunner.class)

public class GeoUtilsTest {

@Mock
private Foo foo;

@Mock
private Bar bar;

@Before
  • foo will be assigned to the variable “f”
  • bar will be assigned to the variable “f”
  • a null pointer exception will be thrown
  • null will be assigned to the variable “f”

Q6. What could be added on line 6 below to ensure that the view with ID R.id.errorMessage is visible on screen and has the contents “Bad password” (select all that apply)?

[email protected] public void testPasswordLengthRuleTriggersErrorMsg() {

onView(withId(R.id.passwordEditText)).perform(typeText(“abc”));

onView(withId(R.id.loginButton)).perform(click());

// What should be added here }

  • 1 onView(withId(R.id.errorMessage), matches(isDisplayed(), withText(“Bad password”)));
  • 12 onView(withId(R.id.errorMessage), matches(isDisplayed()))

    .check(matches(withText(“Bad password”)));
  • 123 onView(withId(R.id.errorMessage))

    .check(matches(isDisplayed()))

    .check(matches(withText(“Bad password”)));
  • 1234 onView(withId(R.id.errorMessage))

    .check(matches(isDisplayed()));

    onView(withId(R.id.errorMessage))

    .check(matches(withText(“Bad password”)));


Q7. Which of the following are true of refactoring (select all that apply)?

  • Refactoring should always introduce new functionality to a code base.
  • Refactoring does not introduce new end-user features.
  • Refactoring should never be done in conjunction with regression testing.
  • Refactoring should not be performed to enhance code modularity.

Q8. What code could be added to insert text into the R.id.welcome TextView (select all that apply)?

  • 1 onView(withId(R.id.welcome).typeText(“abc”);
  • 1 onView(matches(withId(R.id.welcome))).check(typeText(“abc”));
  • 1 onView(withId(R.id.welcome)).perform(typeText(“abc”));
  • 1 perform(typeText(“abc”)).onView(withId(R.id.welcome);

Q9. What is the purpose of regression testing (select all that apply)?

  • to check that changes to a code base have not caused the development schedule to regress
  • to check that changes to a code base have not introduced bugs in previously working code
  • to guarantee that changes to a code base have not introduced bugs in previously working code
  • to check that changes to a code base have not introduced changes in expected behavior of interfaces

Q10. Which of the following are non-functional properties (select all that apply)?

  • how fast a method executes
  • how extensible a method is
  • how secure a method is
  • how much memory a method consumes

Week 3: Engineering Maintainable Android Apps Coursera Quiz Answers

Quiz 1: Security I Quiz

Q1. Which of the following is true of the economy of mechanism design principle (select all that apply)?

  • Using less complicated code to implement the same functionality simplifies security audits.
  • Using less code to implement the same functionality simplifies security audits.
  • Using less code to implement the same functionality will always mean that the code is less extensible and modular.

Q2. Assuming that “runner” is the only implementation of Runner and never needs to be changed, which of the following refactorings of the code shown below would best demonstrate the economy of mechanism design principle (select all that apply)?

  • 12345678910111213141516171819202122232425262728

public class DataHandler {

public interface Runner {

public void run(Runnable r);

}

private final ExecutorService executor = Executors.newFixedThreadPool(1);

private final Runner runner = new Runner() {

public void run(Runnable q){

  • 1234567891011121314151617181920212223242526272829303132333435

public class DataHandler {

public interface Runner {

public void run(Runnable r);

}

private class MyRunner {

public void run(Runnable q){

executor.submit(q);

}

  • 1234567891011121314151617181920212223

public class DataHandler {

private ExecutorService executor;

public DataHandler() {

executor = Executors.newFixedThreadPool(1);

runner = new MyRunner();

}

public void runIt(ExecutorService r, Runnable q){

  • 1234567891011121314

public class DataHandler {

private final ExecutorService executor = Executors.newFixedThreadPool(1);

public void fetchData() {

executor.submit(new FetchDataTask());

}

public void writeData() {

executor.submit(new WriteDataTask());

  • 1234567891011121314151617

public class DataHandler { private ExecutorService executor;

public DataHandler(ExecutorService ex){

executor = ex; }public void fetchData() {

executor.submit(new FetchDataTask());

Q3. Which of the following are reasons why the principle of least privilege is important (select all that apply)?

  • Each privilege that your code possesses creates an additional security responsibility to protect that privilege.
  • Each privilege that your code possesses increases the memory consumption of your application.
  • Each privilege that your code possesses increases the capabilities of your app and makes development faster.

Q4. In Android, which of the following are true of apps that do not apply the principle of least privilege (select all that apply)?

  • They increase build times.
  • They increase the chance that an app will gain access to a capability that requires a uses-permission without declaring the associated uses-permission.
  • They make development easier by allowing the developer to use any device capability they want without having to change the manifest.
  • They consume more space on disk.

Q5. Which of the following could be examples of secure defaults (select all that apply)?

  • encrypting data that the user has explicitly flagged as sensitive
  • using a default username and password to protect data until the user sets their own password
  • forcing the user to set a password on first use

Q6. Why are secure defaults important (select all that apply)?

  • A user may assume that the default settings are secure.
  • A user may not know there are any default settings to change.
  • A user may not have the expertise to change default settings in a secure manner.
  • A user may not bother changing default settings.

Q7. Which of the following is an example of secure defaults (select all that apply)?

  • 12345678910

Map storageEngines = new HashMap<>();

public void init() {

storageEngines.put(“secure”, new EncryptedStorageEngine());

storageEngines.put(“plain”, new PlainTextStorageEngine()); }

public void store(String type, String data){

storageEngines.get(type).store(data); }

  • 123456789101112131415

Map storageEngines = new HashMap<>();

public void init() {

storageEngines.put(“secure”, new EncryptedStorageEngine());

storageEngines.put(“plain”, new PlainTextStorageEngine()); }

public void store(String type, String data){

if(storageEngines.get(type)!=null){

storageEngines.get(type).store(data);

  • 1234567891011121314151617

Map storageEngines = new HashMap<>();

private encryptedEngine = new EncryptedStorageEngine();

public void init() {

storageEngines.put(“secure”, encryptedEngine);

storageEngines.put(“plain”, new PlainTextStorageEngine()); }

public void store(String type, String data){

Q8. A number of recent news articles have highlighted apps that asked for a large number of uses-permissions. Which design principle are these apps most likely to violate (select all that apply)?

  • Secure Defaults
  • Complete Mediation
  • Least Privilege
  • Economy of Mechanism

Q9. What is wrong with the code below (select all that apply)?

123456789101112

public static int SECURE = 1;

public static int MOST_SECURE = 2;

public static int INSECURE = 0;

public void sendData(int securityLevel, String data){

if(securityLevel > 0){

sendEncrypted(data);

}

else if(securityLevel == 0){

sendPlainText(data);

  • In Java, new integer variables are initialized to zero, which will cause the default behavior to be insecure.
  • The flags for the security levels are not final, which could lead to runtime changes of their values and unexpected behavior.

Q10. When is it appropriate to ignore these security principles in order to develop new functionality (select all that apply)?

  • if ignoring them leads to improved performance
  • never
  • if ignoring them helps meet a deadline

Week 4: Engineering Maintainable Android Apps Coursera Quiz Answers

Quiz 1: Security II Quiz

Q1. Which of the following are ways that Android protects your app (select all that apply)?

  • It ensures that only secure apps can send Intents to your app.
  • It ensures data that is stored privately by your app is not accessible to other apps.
  • It ensures that security keys that are embedded in your app’s binary cannot be accessed by the owner of the device.
  • It ensures that the user of the device cannot access your app’s secret preferences.

Q2. What is the potential security issue with the code shown below (select all that apply)?

12345678910111213141516171819

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

// Get the intent that started this activity
Intent intent = getIntent();
String uri = intent.getStringExtra("uri");
startDownload(uri);
  • The code may lead to storing sensitive data on the SD card.
  • The code may lead to a privilege escalation if the calling app does not have the Internet permission.
  • The code may lead to a buffer overflow in the app.
  • The code may lead to a null pointer exception being thrown.

Q3. Security mistakes are made due to which of the following reasons (select all that apply)?

  • The inherent complexity of software makes it difficult not to make mistakes.
  • Popular software design patterns that improve extensibility and modularity always reduce security.
  • Software developers are never given sufficient time and resources to complete projects and make the code secure.
  • Most developers are lazy and do not care about security.
  • A small number of unskilled software developers typically introduce all security vulnerabilities.

Q4. On an Android device, when is a Linux user account created (select all that apply)?

  • when an app is launched
  • when someone sets a passcode
  • when an app is installed
  • when an app requests a permission

Q5. Which of the following are true on Android (select all that apply)?

  • Apps can declare new permissions that other apps can use.
  • There is a limited set of permissions that can be used.
  • An app can provide access to a privileged resource to another app.
  • An app can not provide access to a privileged resource to another app unless the other app also has the appropriate uses-permission.
Conclusion:

I hope this Engineering Maintainable Android Apps Coursera Quiz Answers would be useful for you to learn something new from the Course. If it helped you, don’t forget to bookmark our site for more Quiz Answers.

This course is intended for audiences of all experiences who are interested in learning about new skills in a business context; there are no prerequisite courses.

Keep Learning!

Get All Course Quiz Answers of Android App Development Specialization

Java for Android Coursera Quiz Answers

Android App Components – Intents, Activities, and Broadcast Receivers Quiz Answers

Android App Components – Services, Local IPC, and Content Providers Quiz Answers

Engineering Maintainable Android Apps Quiz Answers

 

5 comments on Engineering Maintainable Android Apps Coursera Quiz Answers

Leave a Reply

Your email address will not be published. Required fields are marked *