mardi 31 mars 2015

I am trying to pass my junit test but keep getting the error nullpointerexception


error: java.lang.NullPointerException at StoryTests.testSaveToDB(StoryTests.java:57)



I am not sure what the error is but do need my test to pass, if anyone has any idea please let me know.



public class StoryTests {

public StoryTests() {
}

ITmagazineSystem testStory;

/**
*
*/
@BeforeClass
public static void setUpClass() {
ITmagazineSystem testStory = new ITmagazineSystem();
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
}

@After
public void tearDown() {
}

@Test
public void testSaveToDB() {
String title = "";
String StoryID = "s200";
String StoryTitle = "ASE";
String StoryType = "Computing";
String StoryContent = "aaaa";
testStory.saveToDB(StoryID, StoryTitle, StoryType, StoryContent);

try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/magazine", "root", ""); // database connection

Statement stmt = (Statement) con.createStatement();

//String searchTitle = "Select StoryTitle from stories where StoryTitle = '" + txtstoryTitle.getText();
String searchTitle = "Select StoryTitle from stories where StoryTitle = '" + StoryTitle + "'";

ResultSet rs = stmt.executeQuery(searchTitle);
while (rs.next()) {

title = rs.getString("StoryTitle");
}
}
catch (Exception e) {
}
assertTrue(title.equals(StoryTitle));
}
}

Aucun commentaire:

Enregistrer un commentaire