Faculty of Engineering and Mathematical Sciences 
Not logged in (login)

help5501

This forum is provided to promote discussion amongst students enrolled in CITS5501 Software Testing and Quality Assurance.

Before posting a question here, you might like to (1) search the forum for previous posts asking the same question, and (2) read the article How To Ask Questions The Smart Way .
And please keep the discussion civil (as required by UWA's Computer Use Policy, #9).
 

Options:
RSS cloud
Jump to:

Project query - question 1(b) - tests and fixtures

3 of 124 articles shown, currently no other people reading this forum.
photo
From: Arran S.
Date: Mon 25th May 2020, 10:54am
Actions: 
        Login-to-reply

 

Hi all,

I was asked:

> In 1b, does the code we write need to be 100% useable or can it be in a slightly 
descriptive manner. My answer involves having some sort of mock object and initializing 
code so I am just wondering if we can short hand some things to make it simpler but the 
intent is clear?

Yes, that's fine - by "code sketch", I mean, write code where you know how to do it; 
otherwise just put down plausible code and a comment on what it's supposed to do.

I'm more interested in your reasoning than in whether your code would work. (Besides 
which, you'd need to make many, many assumptions in order to write workable code, 
anyway.)

cheers

Arran

Project query - question 1(b) - tests and fixtures

photo
From: ANONYMOUS
Date: Wed 27th May 2020, 9:41am
Actions: 
        Login-to-reply

 

Hi Arran, sorry just to clarify - if we are using mocks then can our syntax follow some rough 
pseudo code which mocks out the relevant class? I just couldn't find any of the relevant Java 
syntax for mocks in the slides so I was just wondering if we could just write a psuedo-code 
style and clarify what we mean below the code snippet. 

Project query - question 1(b) - tests and fixtures

photo
From: Arran S.  O.P.
Date: Wed 27th May 2020, 10:59am
Actions: 
        Login-to-reply

 

ANONYMOUS wrote:

> Hi Arran, sorry just to clarify - if we are using mocks then can our syntax follow some rough 
> pseudo code which mocks out the relevant class? I just couldn't find any of the relevant Java 
> syntax for mocks in the slides so I was just wondering if we could just write a psuedo-code 
> style and clarify what we mean below the code snippet. 


Hi -

Yes, exactly that. Pseudocode, or pseudocode interspersed with comments, is the best way to show 
this. (Anyone who does know how to use a mock library is welcome to do so, but it won't be worth any 
extra marks.)

The syntax for creating mocks varies a lot with the exact mock library you're using. (If you're 
interested, there are some examples showing the use of common Java mock frameworks here: 
https://www.baeldung.com/mockito-vs-easymock-vs-jmockit.)

Since creating mocks can be a bit fiddly, in terms of details, and since not everyone doing the unit 
has Java programming skills, in lectures we have just given the broad gist of how mocks work.

I will mention, though, that simple mocks are fairly straightforward to create yourself if you ever 
need to.

e.g. If your code being tested is supposed to call a "submitForm" method at some point, and you want 
to find out whether it did so, you might use a mock class that looked something like this:

class MockForm {
  boolean wasSubmitted = false;

  public void submitForm() {
    wasSubmitted = true;
  }
}

This is the sort of mock we called a "spy" -- it's there to check whether submitForm() was called. 
And at the end of the test, our expected result would be that wasSubmitted is set to true.

I hope that helps - let me know if you need any other clarification.

cheers

Arran

 
This Page


Program written by: [email protected]
Feedback welcome
Last modified: 11:27am Sep 21 2020