androidiosnfce2e-testing

How to test nfc flows e2e on real mobile devices automated


I like to write a test for an ios/android app which needs a NFC card for a login auth.

Ive searched a lot online and all answers at the end are like: it isnt possible to mock or fake.

I ask me now, are Im the only one on this planet who uses nfc and would like to test this flow automated?

Is it only possible by accessing the codebase directly or doing this flow by hand?

Is there no way for a automated e2e test, with any frameworke like appium for example, with real devices and nfc cards?

All the best and thanks.


Solution

  • There are a number of possible ways I can think to automatically test NFC, but non of them are easy and I've not tried any of these.

    Some of these also depend a bit what type of data you are storing and what type Tag you are using.

    1. There are hints in the Android source code about some level of NFC testcode e.g.

      Hidden API createMockTag

      NFC Tests

      Hardware level NFC Tests

      So I believe if you build your own Rom for a device/emulator then you could possibly create your own NFC system that responded with Mocked data instead of talking to the hardware to get it.

    2. It is possible to emulate some NFC Tags with other NFC hardware, so you could possible have another piece of hardware positioned against real hardware and program the emulated Tag to respond correctly to your tests e.g.

      Android hardware with HCE (I'm not sure you will have enough control of the field state to make it appear in range and then disappear with this)

      Some of the Reader chips like PN532 offer some emulation capability, either from a USB reader driven from a PC or attached to something like an Arduino. The PN532 does offer enough low level access to make the Tag appear and disappear from the field.

    3. Creating a electronic device to move a real Tag in to range e.g.

      An Arduino with a servo motor with a Tag stuck on to it.

    All of these would require you test framework to do some setup before running a test.