You are not alone. Articles are really weird in English, and for every rule that exists, there are lots of exceptions that break it. However, here is a general rule that explains these examples.
Consider that there are three cases for articles - definite, indefinite, and general/no article.
Definite
Using a definite article like the indicates a specific singular or plural noun or a specific instance of that noun. Using a definite article signals that it matters which instance of the noun you are talking about. Here are some examples:
- The book fell off the table.
- The boy climbed a tree.
- Did you do the homework?
These are all talking about very specific nouns. There is exactly one book, table, boy, and piece of homework being discussed, and in context, it would be very clear what that is. You could also have plural nouns:
- Please give me the tomatoes.
- Could you ask the girls to come inside?
- How much money do you want for the shirts?
Again, each of these sentences are referring to specific tomatoes, girls, or shirts. The items are being referred to as a group, but it is still clear and important which ones are meant.
If I say "Please give me the tomatoes." I probably want you to pick up 2 or more tomatoes that are close to you. I'm not asking you to go to the store and buy new tomatoes. Which tomatoes I am referring to matters in this sentence.
Other definite articles and qualifiers might include that, those, these, this, and possessive pronouns like my, your, and hers. Here are some examples with these other definite qualifiers:
- My book fell off the table. - Which book? My book! You know which one it is. Which table? The table! It's a specific table being talked about.
- That boy climbed a tree. - This indicates a specific boy.
- Did you do your homework? - I'm not asking you if you did my homework or homework in general. I'm asking about your homework. It's more specific.
- Please give me those tomatoes. - Same explanation as above.
Indefinite
Using an indefinite article like a or an indicates an unspecified version of the noun. It says "The category of noun is important but it doesn't matter which specific one is being talked about."
- A book fell off the table.
- The boy climbed a tree.
- Please give me a tomato.
- Could you ask a student to carry this box.
In these, it doesn't matter which specific item/person is being talked about, just that they are in the stated category. For example, "Please give me a tomato," means that it doesn't matter which tomato is given. It could be any tomato.
When we say "The boy climbed a tree," the boy has a definite article, so it matters which boy it was, but the tree has an indefinite article, so it doesn't matter which tree he climbed.
Other indefinite qualifiers include some, or number qualifiers like one or a few. Here are some examples of these:
- Could you pass me some tomatoes?
- A few books fell off the table.
- How much money do you want for one shirt.
In each of these, it doesn't matter which specific tomatoes, books, or shirt are being talked about. Indefinite qualifiers can also be part of a phrase with a definite qualifier, which gets confusing. Here are some examples of that.
- Could you pass me some of the tomatoes? - This means there is a specific set or pile of tomatoes, but it doesn't matter which ones are passed specifically.
- One of the boys climbed a tree. - This means that there is a specific group of boys, but it doesn't matter (or is not known) which one of them climbed the tree.
No Article
Using no article at all is the most broad. It often refers to an abstract group or category rather than anything specific. It can be used to make general statements where the number of nouns doesn't matter. (This is different from an indefinite article, which almost always communicates how many of the noun is being discussed.)
- Dogs love to run and play.
- Boys climbed the tree all day.
- I love tomatoes!
- Shirts are $20 each.
In each of these, it doesn't matter which specific dogs, boys, tomatoes, or shirts are being discussed. It also doesn't matter how many are being talked about. We don't know how many boys climbed the tree, and it's not important for the sentence.
Notice that leaving out the article only usually happens for plural nouns. Most singular nouns need an article or some other qualifier.
Conclusion
In your examples, teacher needs an article or other qualifier because it's a singular noun. That article could be definite or indefinite depending on the context.
students may or may not need an article depending on meaning. When you leave out the article, you communicate that it's not important which students were having a test or how many students there were. If those things were important to the meaning, then it would be needed to include an article or qualifier.