what are automated testing code example

Example 1: which test should be automated

We can't and shouldn't automate every test case
I would choose automation over manual
-If it is repetitive like data driven
test cases that are supposed to be tested against
multiple test data.
-If the test cases are high priority test cases
-If the functionality is critical functionality
-If the test cases are too long and too difficult to execute.
-I would automate smoke test cases and also
-I would automate regression test cases as much as possible
based on the priority

Also some tests are not the only candidates 
for automation. 
Tasks such as setting up or creating test data
for manual exploratory testing are also great
candidates for automation.

Example 2: which test can be automated

functional tests (positive/negative, UI) 
smoke tests 
regression tests 
integration tests 
API
Database
end to end testing 
data driven