Concerning the [Pearson chi-square test](http://en.wikipedia.org/wiki/Pearson%27s_chi-squared_test) there seems to be a subtle difference between the goodness-of-fit test and the test of independence.

What is confusing is that both tests seem to be calculated in a very similar way.

My question: What is the real difference and how to handle that in practice?

(NB: This is question is related, yet not the same: [Test of independence vs test of homogeneity](https://stats.stackexchange.com/questions/77634/test-of-independence-vs-test-of-homogeneity))