0

We are new to JPos Library, and we wanted to automate testcases which needs peripheral interactions.

To automate the tests with multiple scenarios, we wanted to bypass the connected peripherals and give mock values to our application.

For e.g. We have a connected 'Scale' to measure the weight, and we wanted to mock the value read from the scale, so that this method,

scale.getWeightUnit()

returns our mock value.

Is it possible in JPos with some configurations?

Andrés Alcarraz
  • 1,570
  • 1
  • 12
  • 21
Thiyaga B
  • 971
  • 1
  • 9
  • 26

3 Answers3

1

Jpos library uses the service class mentioned in jpos.xml These service class can be in an external pos.jar ( should be in classpath) and created during runtime. e.g IBM gives a ibmpos.jar file, which has service implemnetation to talk to the peripherals.

So to mock the services, edit the jpos.xml file, create your own service implementation to return the mock values and add the implementation classes in classpath.

and also you need to fire the dataOccured event in the service implementation class to mock the hardware event (e.g. to mock scanned event for a scanner)

Thiyaga B
  • 971
  • 1
  • 9
  • 26
0

If you want to bypass the connected peripherals completely (as in, skip all the JPos part) you could create a mock class that has the methods you use stubbed.

See here: Java - How to use stubs in JUnit

Camile
  • 124
  • 9
  • We are not using JUnit, we are doing an end to end testing from UI, and we want to mock the hardware input to our java code, – Thiyaga B May 02 '18 at 09:36
  • Do you want to fake HW input and run JPos as usual, or is the difference just the UI part? If it's the latter, what are you testing the UI with and what library are you using to do the UI? If you want to 'imitate' valid JPos returns then you could still use stubs, although you would probably have to replace the library with your fake one for the duration of testing (this way your original code is left unchanged and doesn't know it's using the fake library). – Camile May 02 '18 at 11:58
  • Its a 'blackbox' testing for our application, where we use selenium to automate the UI interactions, since we cannot touch any of the code or replace any libraries, we are looking for fake HW input. – Thiyaga B May 02 '18 at 12:16
  • I'm not an expert so I might be wrong here, but I think you won't be able to configure JPos to help you with that. You might need to create a test platform that'd pose as your peripheral (for example an arduino or a raspberry pi running a simple app), but it'd have to follow JPos protocol. By no means I know the definite answer at this point and these are just suggestions. – Camile May 02 '18 at 15:01
0

I usually just implement a dummy JavaPOS service in such cases. You could just return a fixed or random value.

  • Hi, welcome to Stack Overflow. A good answer explains how to achieve the desired result. Often including sample code. As you progress through your Stack Overflow career you'll come to appreciate and be rewarded for quality answers. – Spangen May 30 '18 at 16:03