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

1 of 124 articles shown, currently no other people reading this forum.
photo
From: Arran S.  O.P.
Date: Wed 27th May, 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

 

Related articles

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


Program written by: [email protected]
Feedback welcome
Last modified:  3:57pm Aug 06 2020