arieslab / jnose

JNose - Java TestSmells Detection
GNU General Public License v3.0
20 stars 8 forks source link

Fix test smell detection: lazy test #10

Closed danielevalverde closed 3 years ago

danielevalverde commented 4 years ago

Definition: Occurs when several test methods check the same method;

Detection: Multiple test methods calling the same production method.

Bugs:

@Test public void unknown_test() { Calculate calcule = new Calculate(); int actual = calcule.add(2, 3);
}

@Test
public void should_not_be_eager_test_two() {
    Calculate calcule = new Calculate();
    assertEquals(calcule.turnOn(),"");
    assertEquals(calcule.turnOff(),"");
}
luana-martins commented 3 years ago

According to the definition, Lazy Test occurs when several test methods check the same method. The test methods do not call the same production method. In the example, you have 3 calls for different production methods calcule.add(2, 3), calcule.turnOn(), and calcule.turnOff(). The creation of an object does not count as an instance of Lazy Test.

@test
public void unknown_test() {
Calculate calcule = new Calculate(); \\ creates an object 
int actual = calcule.add(2, 3); \\ calls the ** add()** method (1)
}

@Test
public void should_not_be_eager_test_two() {
  Calculate calcule = new Calculate(); \\ creates an object 
  assertEquals(calcule.turnOn(),""); \\ calls the ** turnOn ** method (2)
  assertEquals(calcule.turnOff(),""); \\ calls the ** turnOff ** method (3)
}

To insert a Lazy Test, you should call the same production method in both test methods. In the next example, the Lazy Test occurs because the method calcule.turnOn() is being called in the unknown_test() and should_not_be_eager_test_two()

@Test 
public void unknown_test() {
         Calculate calcule = new Calculate(); \\ creates an object 
         int actual = calcule.add(2, 3); \\ calls the ** add ** method (1)
         assertEquals(calcule.turnOn(),""); \\ calls the ** turnOn ** method (2)
}

@Test
public void should_not_be_eager_test_two() {
    Calculate calcule = new Calculate(); \\ creates an object 
    assertEquals(calcule.turnOn(),""); \\ calls the ** turnOn ** method (2)
    assertEquals(calcule.turnOff(),""); \\ calls the ** turnOff ** method (3)
}
danielevalverde commented 3 years ago

Hey @luana-martins

Sorry, but I will have to move this issue to "Doing" again. The problem found was that: On the search "By Test smell" is returnig the nome of the production method called instead of the test names that do the call for this methods.