The "Worst Answer"

How Can Testing Be Bad?

An imaginary programming test question
This answer doesn't attempt to catch errors or release resources used, the variable names are quite terse and there is an SQL select statement rather than a call to a stored procedure.

Would the candidate write production code this way? Possibly catch the error further up the program, allow the garbage collector to eventually dispose of the database resources left in use and "I never use stored procedures as I don't see the point"

Instead of helping the recruiter, this answers starts a discussion which probably becomes an argument between the recruiter and the candidate.

Answered The Question And Nothing More

This is probably the worst answer as it works but is not production ready.

This could be proof that the candidate doesn't know how to write proper code or that the candidate thought that all that was wanted was a code fragment to prove that he has used the items under test.

The tester is left with almost as many questions as when he started, what would the candidate's code be like when working for real?

Answer C#

    protected void LoadDataAnswer2(String dbase, DataTable result)
        SqlConnection conn = new SqlConnection(dbase);
        SqlCommand cmd = new SqlCommand();
        conn.Open();cmd.Connection = conn; cmd.CommandType = CommandType.Text;
        cmd.CommandText = @"SELECT Company,CompanyTicker,Keypoints,SharePriceCat,MinPrice,
                     FROM StockTickers WHERE ShareIndex = 'FTSE 100'";
        SqlDataReader dr = cmd.ExecuteReader(); result = new DataTable(); result.Load(dr);

Answer SQL

Candidates point of view - It's only a test so I have embedded the SQL into the C#, in the real world I would use a stored proc or possibly a view or whatever the company policy is. But that's not the point of this test.