Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add passing tests and test duration #80

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class LogstashConfiguration extends GlobalConfiguration
private Boolean enabled;
private boolean dataMigrated = false;
private boolean enableGlobally = false;
private boolean recordingPassingTests = false;
private boolean milliSecondTimestamps = true;
private transient LogstashIndexer<?> activeIndexer;

Expand Down Expand Up @@ -82,6 +83,16 @@ public void setEnableGlobally(boolean enableGlobally)
this.enableGlobally = enableGlobally;
}

public void setrecordingPassingTests(boolean recordingPassingTests)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Camel case

{
this.recordingPassingTests = recordingPassingTests;
}

public boolean isrecordingPassingTests()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camel case

{
return recordingPassingTests;
}

public boolean isMilliSecondTimestamps()
{
return milliSecondTimestamps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ public class BuildData {
private final static Logger LOGGER = Logger.getLogger(MethodHandles.lookup().lookupClass().getCanonicalName());
public static class TestData {
private int totalCount, skipCount, failCount, passCount;
private List<FailedTest> failedTestsWithErrorDetail;
private List<ExecutedTest> failedTestsWithErrorDetail;
private List<String> failedTests;

public static class FailedTest {
private List<ExecutedTest> passedTestsWithErrorDetail;
private List<String> passedTests;

public static class ExecutedTest {
private final String fullName, errorDetails;
public FailedTest(String fullName, String errorDetails) {
private final float duration;
public ExecutedTest(String fullName, String errorDetails, float duration) {
super();
this.fullName = fullName;
this.errorDetails = errorDetails;
this.duration = duration;
}

public String getFullName()
Expand Down Expand Up @@ -103,6 +108,8 @@ public TestData(Action action) {
totalCount = skipCount = failCount = 0;
failedTests = Collections.emptyList();
failedTestsWithErrorDetail = Collections.emptyList();
passedTests = Collections.emptyList();
passedTestsWithErrorDetail = Collections.emptyList();
return;
}

Expand All @@ -112,10 +119,24 @@ public TestData(Action action) {
passCount = totalCount - skipCount - failCount;

failedTests = new ArrayList<String>();
failedTestsWithErrorDetail = new ArrayList<FailedTest>();
for (TestResult result : testResultAction.getFailedTests()) {
failedTests.add(result.getFullName());
failedTestsWithErrorDetail.add(new FailedTest(result.getFullName(),result.getErrorDetails()));
failedTestsWithErrorDetail = new ArrayList<ExecutedTest>();
testListFill((List<TestResult>) testResultAction.getFailedTests(), failedTests, failedTestsWithErrorDetail);

LogstashConfiguration configuration = LogstashConfiguration.getInstance();
if (configuration.isrecordingPassingTests()) {
passedTests = new ArrayList<String>();
passedTestsWithErrorDetail = new ArrayList<ExecutedTest>();
testListFill((List<TestResult>) testResultAction.getPassedTests(), passedTests, passedTestsWithErrorDetail);
} else {
passedTests = Collections.emptyList();
passedTestsWithErrorDetail = Collections.emptyList();
}
}

private void testListFill(List<TestResult> testResults, List<String> testNames, List<ExecutedTest> testDetails) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the signature of the method
List<? extends TestResult> testResults, List<String> testNames, ...
Then you don't need the type cast when you call the method

for (TestResult result : testResults) {
testNames.add(result.getFullName());
testDetails.add(new ExecutedTest(result.getFullName(),result.getErrorDetails(), result.getDuration()));
}
}

Expand All @@ -139,11 +160,21 @@ public int getPassCount()
return passCount;
}

public List<FailedTest> getFailedTestsWithErrorDetail()
public List<ExecutedTest> getFailedTestsWithDetail()
{
return failedTestsWithErrorDetail;
}

public List<ExecutedTest> getPassedTestsWithDetail()
{
return passedTestsWithErrorDetail;
}

public List<String> getPassedTests()
{
return passedTests;
}

public List<String> getFailedTests()
{
return failedTests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
</f:entry>
<f:entry title="Enable Globally" field="enableGlobally" description="This will not enable it for pipeline jobs.">
<f:checkbox/>
</f:entry>
<f:entry title="Enable Globally" field="recordingPassingTests" description="This will record all passing tests in addition to failing tests.">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title is wrong

<f:checkbox/>
</f:entry>
<f:entry title="Use millisecond time stamps" field="milliSecondTimestamps">
<f:checkbox default="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void before() throws Exception {
when(mockTestResultAction.getTotalCount()).thenReturn(0);
when(mockTestResultAction.getSkipCount()).thenReturn(0);
when(mockTestResultAction.getFailCount()).thenReturn(0);
when(mockTestResultAction.getPassedTests()).thenReturn(Collections.emptyList());
when(mockTestResultAction.getFailedTests()).thenReturn(Collections.emptyList());

when(mockProject.getName()).thenReturn("LogstashWriterTest");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class BuildDataTest {
+ "\"rootProjectName\":\"RootBuildDataTest\",\"rootFullProjectName\":\"parent/RootBuildDataTest\","
+ "\"rootProjectDisplayName\":\"Root BuildData Test\",\"rootBuildNum\":456,\"buildVariables\":{},"
+ "\"sensitiveBuildVariables\":[],\"testResults\":{\"totalCount\":0,\"skipCount\":0,\"failCount\":0, \"passCount\":0,"
+ "\"passedTests\":[], \"passedTestsWithErrorDetail\":[],"
+ "\"failedTests\":[], \"failedTestsWithErrorDetail\":[]}}";

@Mock AbstractBuild mockBuild;
Expand Down Expand Up @@ -99,6 +100,7 @@ public void before() throws Exception {
when(mockTestResultAction.getTotalCount()).thenReturn(0);
when(mockTestResultAction.getSkipCount()).thenReturn(0);
when(mockTestResultAction.getFailCount()).thenReturn(0);
when(mockTestResultAction.getPassedTests()).thenReturn(Collections.emptyList());
when(mockTestResultAction.getFailedTests()).thenReturn(Collections.emptyList());

when(mockProject.getName()).thenReturn("BuildDataTest");
Expand Down Expand Up @@ -247,6 +249,7 @@ public void constructorSuccessTestFailures() throws Exception {
when(mockTestResultAction.getSkipCount()).thenReturn(0);
when(mockTestResultAction.getFailCount()).thenReturn(1);
when(mockTestResultAction.getFailedTests()).thenReturn(Arrays.asList(mockTestResult));
when(mockTestResultAction.getPassedTests()).thenReturn(Arrays.asList(mockTestResult));

// Unit under test
BuildData buildData = new BuildData(mockBuild, mockDate, mockListener);
Expand All @@ -256,9 +259,36 @@ public void constructorSuccessTestFailures() throws Exception {
Assert.assertEquals("Incorrect test results", 123, testResults.getTotalCount());
Assert.assertEquals("Incorrect test results", 0, testResults.getSkipCount());
Assert.assertEquals("Incorrect test results", 1, testResults.getFailCount());
Assert.assertEquals("Incorrect test details count", 1, testResults.getFailedTestsWithErrorDetail().size());
Assert.assertEquals("Incorrect failed test error details", "ErrorDetails Test", testResults.getFailedTestsWithErrorDetail().get(0).getErrorDetails());
Assert.assertEquals("Incorrect failed test fullName", "Mock Full Test", testResults.getFailedTestsWithErrorDetail().get(0).getFullName());
Assert.assertEquals("Incorrect test details count", 1, testResults.getFailedTestsWithDetail().size());
Assert.assertEquals("Incorrect failed test error details", "ErrorDetails Test", testResults.getFailedTestsWithDetail().get(0).getErrorDetails());
Assert.assertEquals("Incorrect failed test fullName", "Mock Full Test", testResults.getFailedTestsWithDetail().get(0).getFullName());


verifyMocks();
verifyTestResultActions();
}

@Test
public void constructorSuccessTestPasses() throws Exception {
TestResult mockTestResult = Mockito.mock(hudson.tasks.test.TestResult.class);
when(mockTestResult.getFullName()).thenReturn("Mock Full Test");
when(mockTestResult.getErrorDetails()).thenReturn("");

when(mockTestResultAction.getTotalCount()).thenReturn(123);
when(mockTestResultAction.getSkipCount()).thenReturn(0);
when(mockTestResultAction.getFailCount()).thenReturn(0);
when(mockTestResultAction.getFailedTests()).thenReturn(Arrays.asList(mockTestResult));

// Unit under test
BuildData buildData = new BuildData(mockBuild, mockDate, mockListener);

TestData testResults = buildData.getTestResults();

Assert.assertEquals("Incorrect test results", 123, testResults.getTotalCount());
Assert.assertEquals("Incorrect test results", 0, testResults.getSkipCount());
Assert.assertEquals("Incorrect test results", 0, testResults.getFailCount());
Assert.assertEquals("Incorrect test results", 123, testResults.getPassCount());
Assert.assertEquals("Incorrect test details count", 1, testResults.getFailedTestsWithDetail().size());

verifyMocks();
verifyTestResultActions();
Expand Down