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


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).

RSS cloud
Jump to:

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

1 of 124 articles shown, currently no other people reading this forum.
From: Arran S.  O.P.
Date: Wed 27th May 2020, 10:59am



> 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: 

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.




Related articles

Project query - question 1(b) - tests and fixtures (all 3) RSS
├─ original   Mon 25th May 2020, 10:54am, Arran S.
├─ reply 1   Wed 27th May 2020, 9:41am, ANONYMOUS
└─ THIS   Wed 27th May 2020, 10:59am, Arran S.  O.P.
This Page

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