TestNG is a Test Runner and lets you do the following:
- Helps you call out specific methods as test methods.
- Helps you define setup and tear down which is like defining entry and exit criteria that are to be met for running your tests.
- Helps you logically group your test methods based on some classification, so that you can run the group of tests easily.
- Helps you define dependencies amongst tests, so that they will mimic how you test manually.
- Helps you build data driven test methods, so that you can run the same test with different sets of data.
- Helps you define how to run tests (Should they be run sequentially or if they can be run concurrently)
- Provides you with some basic reporting and also lets you build custom reporting.
- Lets you define listeners so that you can do some adhoc processing based on different events (for e.g., test started, test finished, test passed, test failed, test skipped etc.,)
and a lot more.
Selenium Grid is a mechanism/utility/tool that helps you run your tests on a remote environment.
It lets you point your tests at the grid and the grid will basically run your tests in a different environment (which needn't be the same as your local desktop).
Since you mentioned appium, here's a typical use case.
Lets say you are trying to run some iOS automation tests, but you only have a windows machine at your disposal.
Had you setup a Grid environment such that it has a node that is running on a OSX machine, then the tests that are spun off by a test runner on your windows machine can be delegated and routed to be executed on the remote OSX machine.
The grid contains two parts to it.
- Hub - Imagine this to be like a manager. It basically gets request to run a new test from your desktop, finds out which of the nodes (attached to it) can run this test (based on the capabilities) and if a match is found, the test is routed to that particular node.
- Node - Imagine this to be like a team member. This is the component that actually does the work of opening up a browser and performing all the user actions that your test is trying to do.