Need suggestions for getting started with Junit

I have not used Junit before and have not done unit testing automatically.

Scenario: We are changing our backend DAO from Sql Server to Oracle. Thus, on the database side, all stored procedures were transformed into an oracle. Now that our code calls these Oracle stored procedures, we want to make sure that the returned data is the same as the sql server stored procedures.

So, for example, I have the following method in the DAO:

  //this is old method. gets data from sql server
  public IdentifierBean getHeadIdentifiers_old(String head){
      HashMap parmMap = new HashMap();
      parmMap.put("head", head);
      List result = getSqlMapClientTemplate().queryForList("Income.getIdentifiers", parmMap);
      return (IdentifierBean)result.get(0);
   }
  //this is new method. gets data from Oracle  
  public IdentifierBean getHeadIdentifiers(String head){
      HashMap parmMap = new HashMap();
      parmMap.put("head", head);
      getSqlMapClientTemplate().queryForObject("Income.getIdentifiers", parmMap);
      return (IdentifierBean)((List)parmMap.get("Result0")).get(0);
   }

Now I want to write a Junit testing method that first calls getHeadIdentifiers_oldand then getHeadIdentifierscompares the returned object (it will have to rewrite the equal and hash in IdentifierBean). The test will pass only when both objects are the same.

( , ) . . , , SPs . , , ...

:

  • ?
  • DAO. DAO DAO JUnit?
  • ( , n00b) ? , DAO .
  • , ? , , ?
  • , - ? , , Junit
+3
4

.

public class OracleMatchesSqlServer extends TestCase {
    public void testHeadIdentifiersShouldBeEqual() throws Exception {
        String head = "whatever your head should be";
        IdentifierBean originalBean = YourClass.getHeadIdentifiers_old(head);
        IdentifierBean oracleBean = YourClass.getHeadIdentifiers(head);
        assertEquals(originalBean, oracleBean);
    }
}

, ; .

. :

public class OracleMatchesSqlServer extends TestCase {
    public void testHeadIdentifiersShouldBeEqual() throws Exception {
        compareIdentifiersWithHead("head1");
        compareIdentifiersWithHead("head2");
        compareIdentifiersWithHead("etc");
    }
    private static void compareIdentifiersWithHead(String head) {
        IdentifierBean originalBean = YourClass.getHeadIdentifiers_old(head);
        IdentifierBean oracleBean = YourClass.getHeadIdentifiers(head);
        assertEquals(originalBean, oracleBean);
    }
}
* Is this a good approach?

.

* I will have multiple DAOs. Do I write the test methods inside the DAO
  itself or for each DAO I should have a separate JUnit Test Class?

DAO; , - , . , , .

* (might be n00b question) will all the test cases be run automatically?
  I do not want to go to the front end click bunch of stuff so that call
  to the DAO gets triggered.

.

* when tests are ran will I find out which methods failed? 
  and for the ones failed will it tell me the test method that failed?

.

* lastly, any good starting points? any tutorials, articles that
  show working with Junit

Dave Astels .

+1

, , ...

?

. , , . , , - , - , , , ?

, , , .

DAO. DAO DAO JUnit?

, OO , , , , . , , ( SO Google , ), . , , - .

( , n00b) ? , , DAO.

IDE: s JUnit, , Eclipse / Run → Junit test. JUnit (setup()testX()tearDown()).

, , ? , , , ?

, Test Driven Development Red-Green-Refactor, , IDE: s . , - , , , . , JUnit , .

, - ? , , Junit

, , :)

+3
0

unit test ( ):

XUnit, Gerard Meszaros

3 . , xUnit. II " ", , . III .

0

Source: https://habr.com/ru/post/1722164/


All Articles