0

How do I test my generateTrend function whether to see data gets updated in the mysql database.I haven't done any testing before and I am still new to Java. Can anyone please help me with this. Thanks for your time.

  public void generateTrend() throws SQLException {

        //Generate Random Market
        Integer[] Values = {-2, -1, 0, 1, 2};
        Random rand = new Random();
        int n;
        int nominalvalue;
        int newnominalvalue;
        int randNum;
        int T;
        int RT;
        for (int i = 0; i <= 12; i++) {//need to run 4 times

            n = rand.nextInt(5);
            randNum = Values[n];

            for (int c = 1; c <= 12; c++) {


                //return T;

                st = con.createStatement();
                rs = st.executeQuery("SELECT * FROM  '" + FS + "'");//select data for each sector//select data for each sector
                while (rs.next()) {
                    String CMF = rs.getString("comapanyName");
                    String ONV = rs.getString("oldNominalValue");
                    String NNV = rs.getString("newNominalValue");
                    // String NS = rs.getString("numberOfShares");
                    // System.out.print(CMH);
                    // System.out.print(CMH);
                    nominalvalue = Integer.parseInt(ONV);
                    //System.out.println(nominalvalue);
                    //System.out.println(Values[n]);
                    //System.out.println(randNum);
                    //System.out.println(c);
                    //int nv = 1;
                    T = randNum / 100;
                    RT = T * nominalvalue;
                    newnominalvalue = nominalvalue - RT;
                    //System.out.println(newnominalvalue);
                    // System.out.println(T);

                    st = con.createStatement();
                    String query05 = "UPDATE " + FS + " SET oldNominalValue='" + nominalvalue + "', newNominalValue='" + newnominalvalue + "'  WHERE comapanyName= '" + CMF + "'";
                    st.executeUpdate(query05);
                }
}
Nuiok1996
  • 3
  • 5
  • 1
    Why not just do a query on the database to see if your method successfully updated your database? – Aiyuni Aug 01 '19 at 17:58
  • Hope the following helps you https://stackoverflow.com/questions/6734410/is-there-a-way-to-run-mysql-in-memory-for-junit-test-cases – pvrforpranavvr Aug 01 '19 at 17:59
  • what about using [dbunit](http://dbunit.sourceforge.net/index.html) –  Aug 01 '19 at 18:50

0 Answers0