Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/com/artos/framework/infra/RunnerTestUnits.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,16 @@ private void runIndividualUnitTest(TestUnitObjectWrapper unit) {
context.getAfterTestUnit().invoke(context.getPrePostRunnableObj().getDeclaredConstructor().newInstance(), context);
notifyGlobalAfterTestUnitMethodExecutionFinished(unit);
}

// Run custom after unit failed method post each failed test unit execution
// If KTF marked test unit is passing then also execute this method because outcome of this unit will be failed
if (context.getCurrentUnitTestStatus() == TestStatus.FAIL || (unit.isKTF() && context.getCurrentUnitTestStatus() == TestStatus.PASS)) {
if (null != t.getMethodAfterFailedUnit()) {
notifyLocalAfterFailedUnitMethodExecutionStarted(t, unit);
t.getMethodAfterFailedUnit().invoke(t.getTestClassObject().newInstance(), context);
notifyLocalAfterFailedUnitMethodExecutionFinished(unit);
}
}

// Run global after unit failed method post each failed test unit execution
// If KTF marked test unit is passing then also execute this method because outcome of this unit will be failed
Expand Down Expand Up @@ -603,6 +613,18 @@ void notifyLocalAfterTestUnitMethodExecutionFinished(TestUnitObjectWrapper unit)
listener.localAfterTestUnitMethodExecutionFinished(unit);
}
}

void notifyLocalAfterFailedUnitMethodExecutionStarted(TestObjectWrapper t, TestUnitObjectWrapper unit) {
for (TestProgress listener : listenerList) {
listener.localAfterFailedUnitMethodExecutionStarted(t, unit);
}
}

void notifyLocalAfterFailedUnitMethodExecutionFinished(TestUnitObjectWrapper unit) {
for (TestProgress listener : listenerList) {
listener.localAfterFailedUnitMethodExecutionFinished(unit);
}
}

void notifyTestUnitExecutionStarted(TestUnitObjectWrapper unit) {
for (TestProgress listener : listenerList) {
Expand Down
6 changes: 6 additions & 0 deletions src/com/artos/framework/infra/ScanTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;
import java.util.stream.Collectors;

import com.artos.annotation.AfterFailedUnit;
import com.artos.annotation.AfterTest;
import com.artos.annotation.AfterTestUnit;
import com.artos.annotation.BeforeTest;
Expand Down Expand Up @@ -110,6 +111,11 @@ private void scanForTestUnits(TestObjectWrapper testObj) {
testObj.setMethodAfterTestCase(method);
continue;
}

// If one method is found then do not accept any other
if (null == testObj.getMethodAfterFailedUnit() && isValidMethod(method, AfterFailedUnit.class)) {
testObj.setMethodAfterFailedUnit(method);
}
}
// move to the upper class in the hierarchy in search for more methods
klass = klass.getSuperclass();
Expand Down
9 changes: 9 additions & 0 deletions src/com/artos/framework/infra/TestObjectWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class TestObjectWrapper {
Method methodAfterTestUnit = null;
Method methodBeforeTestCase = null;
Method methodAfterTestCase = null;
Method methodAfterFailedUnit = null;
List<TestUnitObjectWrapper> testUnitList = null;

// TestPlan
Expand Down Expand Up @@ -324,6 +325,14 @@ public Method getMethodBeforeTestCase() {
public void setMethodBeforeTestCase(Method methodBeforeTestCase) {
this.methodBeforeTestCase = methodBeforeTestCase;
}

public Method getMethodAfterFailedUnit() {
return methodAfterFailedUnit;
}

public void setMethodAfterFailedUnit(Method methodAfterFailedUnit) {
this.methodAfterFailedUnit = methodAfterFailedUnit;
}

public Method getMethodAfterTestCase() {
return methodAfterTestCase;
Expand Down
12 changes: 12 additions & 0 deletions src/com/artos/framework/listener/ExtentReportListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,18 @@ public void localAfterTestUnitMethodExecutionFinished(TestUnitObjectWrapper unit
// TODO Auto-generated method stub

}

@Override
public void localAfterFailedUnitMethodExecutionStarted(TestObjectWrapper t, TestUnitObjectWrapper unit) {
// TODO Auto-generated method stub

}

@Override
public void localAfterFailedUnitMethodExecutionFinished(TestUnitObjectWrapper unit) {
// TODO Auto-generated method stub

}

@Override
public void testUnitExecutionStarted(TestUnitObjectWrapper unit) {
Expand Down
12 changes: 12 additions & 0 deletions src/com/artos/framework/listener/JUnitReportListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,18 @@ public void localAfterTestUnitMethodExecutionFinished(TestUnitObjectWrapper unit
// TODO Auto-generated method stub

}

@Override
public void localAfterFailedUnitMethodExecutionStarted(TestObjectWrapper t, TestUnitObjectWrapper unit) {
// TODO Auto-generated method stub

}

@Override
public void localAfterFailedUnitMethodExecutionFinished(TestUnitObjectWrapper unit) {
// TODO Auto-generated method stub

}

@Override
public void globalBeforeTestCaseMethodExecutionStarted(String methodName, TestObjectWrapper t) {
Expand Down
10 changes: 10 additions & 0 deletions src/com/artos/framework/listener/TestExecutionEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,16 @@ public void localAfterTestUnitMethodExecutionStarted(TestObjectWrapper t, TestUn
public void localAfterTestUnitMethodExecutionFinished(TestUnitObjectWrapper unit) {
// logger.trace("\n---------------- Local After Test Unit Method Finished -------------------");
}

@Override
public void localAfterFailedUnitMethodExecutionStarted(TestObjectWrapper t, TestUnitObjectWrapper unit) {
logger.info("\n=> " + t.getMethodAfterFailedUnit().getName() + "(context)");
}

@Override
public void localAfterFailedUnitMethodExecutionFinished(TestUnitObjectWrapper unit) {
// logger.trace("\n---------------- Local After Failed Unit Method Finished -------------------");
}

@Override
public void testUnitExecutionStarted(TestUnitObjectWrapper unit) {
Expand Down
12 changes: 12 additions & 0 deletions src/com/artos/framework/listener/UDPReportListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ public void localAfterTestUnitMethodExecutionFinished(TestUnitObjectWrapper unit
// TODO Auto-generated method stub

}

@Override
public void localAfterFailedUnitMethodExecutionStarted(TestObjectWrapper t, TestUnitObjectWrapper unit) {
// TODO Auto-generated method stub

}

@Override
public void localAfterFailedUnitMethodExecutionFinished(TestUnitObjectWrapper unit) {
// TODO Auto-generated method stub

}

@Override
public void globalBeforeTestCaseMethodExecutionStarted(String methodName, TestObjectWrapper t) {
Expand Down
17 changes: 17 additions & 0 deletions src/com/artos/interfaces/TestProgress.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,23 @@ public interface TestProgress {
* @see TestUnitObjectWrapper
*/
public void localAfterTestUnitMethodExecutionFinished(TestUnitObjectWrapper unit);

/**
* Method is called after local {@code AfterFailedUnit} method execution starts
*
* @param t test object wrapper
* @param unit test unit object wrapper
* @see TestUnitObjectWrapper
*/
public void localAfterFailedUnitMethodExecutionStarted(TestObjectWrapper t, TestUnitObjectWrapper unit);

/**
* Method is called after local {@code AfterTestUnit} method execution starts
*
* @param unit test unit object wrapper
* @see TestUnitObjectWrapper
*/
public void localAfterFailedUnitMethodExecutionFinished(TestUnitObjectWrapper unit);

// ==========================================================
// Test Case Before and After
Expand Down