arieslab / jnose

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

Fix General Fixture #20

Closed danielevalverde closed 3 years ago

luana-martins commented 3 years ago

Description. General Fixture (GF) occurs when a test case fixture is too general and the test methods only access part of it. A test setup/fixture method that initializes fields that are not accessed by test methods indicates that the fixture is too generalized. A drawback of it being too general is that unnecessary work is being done when a test method is run.

Detection. Not all fields instantiated within the setUp method of a test class are utilized by all test methods in the same test class.

Example. `int numero1, numero2;

@Before
public void setUp() throws Exception {
    numero1 = 2;
    numero2 = 2; // it is not used by all test methods, i.e. it should be in usaUm() method 
}

@Test
public void usaTodos(){
    assertEquals("explanation", numero1, numero2);  // uses both fields instantiated within the setUp method
}

@Test
public void usaUm(){
    assertEquals("explanation", numero1, 2); // uses only the numero1 field
}`

Problem. The current detection highlights all methods that do not use one of the fields instantiated in the setup. However, the problem is in the field in the setup method that should not be there. Therefore, the detection should identify which fields are not being used in the setup method, and highlight these lines.
Current detection - It highlights the whole usaUm method (and other methods that do not use numero1 and numero2) Solution - It should highlight only the line where the field numero2 is being instantiated in the setup method.