Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-murzinov committed Nov 1, 2014
1 parent 47ea56f commit 3c912fd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
45 changes: 19 additions & 26 deletions NUnitAllureAdapter/AllureEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@

namespace NUnitAllureAdapter
{
public class AllureEventListener : EventListener
public class AllureEventListener : EventListenerAdapter
{
private static readonly ILog Logger = LogManager.GetLogger(typeof (AllureEventListener));

private static readonly OrderedDictionary SuiteStorage =
new OrderedDictionary();

private static readonly bool WriteOutputToAttachmentFlag;
private static readonly bool TakeScreenShotOnFailedTestsFlag;

private readonly Allure _lifecycle = Allure.Lifecycle;

private StringBuilder _log = new StringBuilder();
private StringBuilder _stdErr = new StringBuilder();
private StringBuilder _stdOut = new StringBuilder();
private StringBuilder _trace = new StringBuilder();

private static readonly bool TakeScreenShotOnFailedTestsFlag;
private static readonly bool WriteOutputToAttachmentFlag;

static AllureEventListener()
{
try
Expand All @@ -43,7 +43,7 @@ static AllureEventListener()
XDocument.Load(path + "/config.xml")
.Descendants()
.First(x => x.Name.LocalName.Equals("results-path"))
.Value;
.Value + "/";

TakeScreenShotOnFailedTestsFlag =
Convert.ToBoolean(XDocument.Load(path + "/config.xml")
Expand All @@ -56,14 +56,20 @@ static AllureEventListener()
.Descendants()
.First(x => x.Name.LocalName.Equals("write-output-to-attachment"))
.Value);

Logger.Error("Initialization completed successfully.\n");
Logger.Error(
String.Format(
"Results Path: {0};\n WriteOutputToAttachmentFlag: {1};\n TakeScreenShotOnFailedTestsFlag: {2}",
AllureConfig.ResultsPath, WriteOutputToAttachmentFlag, TakeScreenShotOnFailedTestsFlag));
}
catch (Exception e)
{
Logger.Error(String.Format("Exception in initialization"), e);
}
}

public void RunStarted(string name, int testCount)
public override void RunStarted(string name, int testCount)
{
try
{
Expand All @@ -79,15 +85,7 @@ public void RunStarted(string name, int testCount)
}
}

public void RunFinished(TestResult result)
{
}

public void RunFinished(Exception exception)
{
}

public void TestStarted(TestName testName)
public override void TestStarted(TestName testName)
{
try
{
Expand Down Expand Up @@ -121,15 +119,15 @@ Assembly asm in AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Co
}
}

public void TestFinished(TestResult result)
public override void TestFinished(TestResult result)
{
try
{
if (result.IsError)
{
if (TakeScreenShotOnFailedTestsFlag)
{
TakeScreenshot();
TakeScreenshot();
}
_lifecycle.Fire(new TestCaseFailureEvent
{
Expand All @@ -141,7 +139,7 @@ public void TestFinished(TestResult result)
{
if (TakeScreenShotOnFailedTestsFlag)
{
TakeScreenshot();
TakeScreenshot();
}
_lifecycle.Fire(new TestCaseFailureEvent
{
Expand Down Expand Up @@ -177,7 +175,7 @@ public void TestFinished(TestResult result)
}
}

public void SuiteStarted(TestName testName)
public override void SuiteStarted(TestName testName)
{
try
{
Expand Down Expand Up @@ -207,7 +205,7 @@ Assembly asm in AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Co
}
}

public void SuiteFinished(TestResult result)
public override void SuiteFinished(TestResult result)
{
try
{
Expand All @@ -220,12 +218,7 @@ public void SuiteFinished(TestResult result)
}
}

public void UnhandledException(Exception exception)
{
Logger.Error(String.Format("UnhandledException"), exception);
}

public void TestOutput(TestOutput testOutput)
public override void TestOutput(TestOutput testOutput)
{
switch (testOutput.Type)
{
Expand Down
1 change: 1 addition & 0 deletions NUnitAllureAdapter/NUnitAllureAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<ItemGroup>
<Compile Include="AllureAdapter.cs" />
<Compile Include="AllureEventListener.cs" />
<Compile Include="EventListenerAdapter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions NUnitAllureAdapter/config.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<config>
<!-- Specify absolute path, otherwise it will be relative to current directory which can lead to unpredictable results -->
<results-path>AllureResults</results-path>
<write-output-to-attachment>true</write-output-to-attachment>
<take-screenshots-after-failed-tests>true</take-screenshots-after-failed-tests>
Expand Down

0 comments on commit 3c912fd

Please sign in to comment.