mercredi 27 avril 2016

What code shouldn't be covered by unit-tests?

  1. Do I need to test delegates-methods? I have class Task, in which there's a method:

    public void setValue(int value, int row, int col) {
      if (col == variableCount + 1) {
          limits.set(row - criterionCount, value);
          return;
      }
      if (row < criterionCount) {
          costs.get(row).set(col, value);
          return;
      }
      if (row >= criterionCount) {
        weights.get(row - criterionCount).set(col, value);
      }
    }
    
    

    This method of class Task was tested.

    I have another class, in which I have a method:

    setText(int value, int row, int col){
      task.setText(value, row, col);
    }
    
    

    Do I need to test it?

  2. How to test an anonymous class? For example:

    field.addKeyListener(new KeyAdapter(){    
      @Override
         public void keyPressed(KeyEvent e){
         field.setText(field.getText().replaceAll("\\D++", ""));    
      }    
    });
    
    

    Am I should to create non Anonymous class.

  3. How can I test pattern State? I have class that might to be in different states. And I have a method that return current state: Look, please:

    @Override
    public TableManager getTableManager() {
      return tableManager;
    }
    
    

    I stay state like this:

    if(isFirstState()){
      tableManager = new FirstState();
    }
    else {
      tableManager = new SecondState();
    }
    
    

    How can I test it? I should to use instanceof in tests?

Aucun commentaire:

Enregistrer un commentaire