A firewall can be either a piece of software (Cisco IOS, IPCop, IPFire, Windows Firewall, etc.) or a hardware component. The goal of a firewall is to allow or disallow in- and outgoing network traffic based on a set of rules (aka firewall rules gathered in a rule base). It tries to prevent hackers, spam, spyware, worms and viruses to reach a computer or (part of a) network.
It can for example be set between your personal computer and the internet. Another possibility is that it can be placed between the database and application servers. There are countless possible setups of firewalls within a network. Underneath, there is an example of a setup of firewalls.
For more info about “How to test … a firewall?” click on the link.