jeudi 4 juin 2015

Testen von Methoden

Hallo,

wie kann ich diese Methode testen?

Java Code:

  1. public ArrayList<Customer> getCustomerTable() throws SQLException {
  2.  
  3. list = new ArrayList<>();
  4.  
  5. Connection con = getConnection();
  6.  
  7. PreparedStatement ps = con.prepareStatement("SELECT customer_id, title, first_name, last_name, company_name, address, house_number, postalcode, city, country, telephone, email FROM Customer");
  8.  
  9. //get customer data from database
  10. ResultSet result = ps.executeQuery();
  11.  
  12. while (result.next()) {
  13. Customer customer = new Customer();
  14.  
  15.  
  16. customer.setCustomer_id(result.getInt("customer_id"));
  17. customer.setTitle(result.getString("title"));
  18. customer.setFirst_name(result.getString("first_name"));
  19. customer.setLast_name(result.getString("last_name"));
  20. customer.setCompany_name(result.getString("company_name"));
  21. customer.setAddress(result.getString("address"));
  22. customer.setHouse_number(result.getString("house_number"));
  23. customer.setPostalcode(result.getString("postalcode"));
  24. customer.setCity(result.getString("city"));
  25. customer.setCountry(result.getString("country"));
  26. customer.setTelephone(result.getInt("telephone"));
  27. customer.setEmail(result.getString("email"));
  28. //store all data into a List
  29. list.add(customer);
  30.  
  31. con.close();
  32. }
  33.  
  34. return list;
  35.  
  36. }


habe von Netbeans Test generieren lassen, aber ich weiss nicht wie ich die Methode wirklich testen kann, also ich weiss nicht welche Informationen ich aus dieser Methode in der Testmethode benutzen muss/kann ?

Test Methode ( von Netbeans generiert )
Java Code:

  1. @Test
  2. public void testGetCustomerTable() throws Exception {
  3. System.out.println("getCustomerTable");
  4. Customer instance = new Customer();
  5. ArrayList<Customer> expResult = null;
  6. ArrayList<Customer> result = instance.getCustomerTable();
  7. assertEquals(expResult, result);
  8. }


Testen von Methoden

0 commentaires:

Enregistrer un commentaire