how can i create a html report for the junit xml report manually? - html

I have run junit and it shows the results in Junit console, then i do a export of the result, it is saved as some test.xml. now i want to generate a html report out of it how do i do it ? MY project is complex and i cant do as a normal
<target name ="test" depends="run-tests">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}\html\"/>
</junitreport>
</target>
anybody any tool that can be used to convert the results in xml to a html format.

Given just the junit xml file (and python) you can convert the xml junit report file into a single self-contained HTML file using junit2html. https://github.com/inorton/junit2html
I had wanted a tool that does this for quite a long time so finally sat down the other day and had a go. It is pure python so should work on any platform as a stand-alone tool.

Not 100% sure what you're asking but heck here's my ant code for doing a JUnit batch test then a HTML report using the XML formatter...
<junit showoutput="on" printsummary="on" fork="false" haltonfailure="false"
failureproperty="unittest.failure">
<classpath>
<pathelement path="${build.classpath}"/>
<pathelement path="${classes}"/>
</classpath>
<batchtest todir="${unittests.results}">
<fileset dir="${classes}">
<include name="${batchtest.prefix}#{test}_test.class" />
</fileset>
<formatter type="xml"/>
</batchtest>
</junit>
<junitreport todir="${unittests.results}">
<fileset dir="${unittests.results}"/>
<report todir="${unittests.results}"/>
</junitreport>
note that the #{test} is because its part of a macrodef within the build.xml file.
From what you said in the question, its unsure if you're using the <formatter type="xml">.
Anyway hope that helps
oh and dont mix your slashes ${reports}\html\" > ${reports}/html/"

Related

How to be alerted of razor view errors

My dotnet core projects build and deploy with no errors, but I could have a honking game breaking exception in a cshtml view that doesn't get picked up at all. In an ideal world I'd have tests checking every crud page, but not on this project, client doesn't have the budget. There's too many views to open them all and check as well (every time)
Is there any way to have the build fail if there's any bad code in the cshtml files?
This will be the default in ASP.NET Core 2.1 since views will be always compiled on build and only dynamically re-compiled on edits.
In the meanwhile, you can add this to your csproj file (built this originally on this GitHub issue):
<Target Name="SetMvcRazorOutputPath">
<PropertyGroup>
<MvcRazorOutputPath>$(IntermediateOutputPath)</MvcRazorOutputPath>
</PropertyGroup>
</Target>
<Target Name="_MvcRazorPrecompileOnBuild"
DependsOnTargets="SetMvcRazorOutputPath;MvcRazorPrecompile"
AfterTargets="Build"
Condition=" '$(IsCrossTargetingBuild)' != 'true' " />
<Target Name="IncludePrecompiledViewsInPublishOutput"
DependsOnTargets="_MvcRazorPrecompileOnBuild"
BeforeTargets="PrepareForPublish"
Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
<ItemGroup>
<_PrecompiledViewsOutput Include="$(MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.dll" />
<_PrecompiledViewsOutput Include="$(MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.pdb" />
<ContentWithTargetPath Include="#(_PrecompiledViewsOutput->'%(FullPath)')"
RelativePath="%(_PrecompiledViewsOutput.Identity)"
TargetPath="%(_PrecompiledViewsOutput.Filename)%(_PrecompiledViewsOutput.Extension)"
CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
</Target>

NoClassDefFoundError when checkstyle is running

I have written a new checkstyle check as a filescanner. I modeled my junits after the code I found in the checkstyle code. The junits run just fine and everything looks good.
But then, I add the check to my project.
<module name="TreeWalker">
<property name="tabWidth" value="4" />
<module name="com.onuspride.codetools.checkstyles.DuplicateClassNames"/>
</module>
and my ant task
<taskdef resource="checkstyletask.properties">
<classpath refid="classpath" />
</taskdef>
<property name="checkstyle.suppressions.file" value="checkstyle/suppressions.xml" />
<property name="translation.severity" value="error" />
<target name="checkStyle" description="TestTask to evaluate the checkstyle system.">
<checkstyle config="checkstyle/checkstyle_checks.xml">
<fileset dir="${msg.src}" includes="**/*.java" />
<formatter type="plain" />
<formatter type="xml" toFile="${msg.build.jar}/checkstyle_errors.xml" />
<classpath refid="classpath" />
</checkstyle>
</target>
the duplicateclassnames class calls several classes in the same jar. For some reason, when ant runs it, ant finds the check class, but can't find the supporting classes, when they are all in the same jar file. here's what i get in ant
[checkstyle] [class]:0: Got an exception - java.lang.NoClassDefFoundError: com/onuspride/codetools/common/classpath/criteria/ClassNameCriteriaCollector
Im stumped. Ive checkd all the dependencies of my jar, they are all in the classpath, I don't understand how it can find one class file but not another in the same jar. Ive done all my dirty little tricks and I just don't get it.
any ideas?
You can do it like following :
Create plugin project and add your custom checks there.
Make appropriate changes to plugin.xml, checkstyle_packages.xml.
Export the project as Deployable Plug-ins and fragments (Export > Plug-in Developement)
Copy the jar file to Eclipse Plugin folde, so no need to install your custom check .
You can go through this tutorial for reference
To reduce effort, download a Sample Check, the file is here under the name net.sf.eclipsecs.sample
Just replace your source in src folder. Before replacing, refer this 3 files in src/net/sf/eclipsecs/sample/checks/ directory as you will need them in your com/onuspride/codetools/checkstyles/ directory :
checkstyle-metadata.properties
checkstyle-metadata.xml
messages.properties
After replacing the code, make appropriate changes in checkstyle_packages.xml file in src/ directory.
Extending Check is described nicely there.

Overriding/merging standard programmatic configuration with config file section

We have a standard set of conventions that we follow for logging from our various applications, and it is sensible to package this configuration as by-code configuration and include in a common assembly.
Occasionally, however, we need to override this config to more efficiently debug production issues. This is more easily accomplished by letting a developer or administrator add an NLog config section, which can be read in and override or add to configuration done programmatically.
Can this be done out of the box with NLog?
I know this isn't by-code (I'm not sure how to do it), but you can use <include> with XML config to override things like variables. Here's a sample that uses Web.config that overrides the "standard" NLog.config for other projects:
Web.config:
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<include file="${basedir}\bin\NLog.config" />
<variable name="fruit" value="Apples" />
</nlog>
</configuration>
NLog.config (that gets copied to bin):
<?xml version="1.0"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<!-- Output Window -->
<target name="debug" xsi:type="Debugger" layout="${fruit}|${level:uppercase=true}|${logger}|${message}"></target>
</targets>
<rules>
<logger name="*" writeTo="debug" />
</rules>
</nlog>

Help Updating XML file using MSBuild Extensions 4 with namespaces

I'm having some trouble getting MSBuild extensions 4.0 to update an XML file once a namespace is involved.
When I have a simple XML file with no namespace then fine, but once i attempt to update an xml file that has a namespace set, then nothing happens .. notice there is no error tho.
Here are the simple ones that work fine
<Project>
<PropertyGroup>
<ApplicationVersion>5.1.500.16</ApplicationVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationVersion>old</ApplicationVersion>
</PropertyGroup>
</Project>
and project file
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TPath>C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks</TPath>
<AssemblyVersion>5.1.500.18</AssemblyVersion>
</PropertyGroup>
<Import Project="$(TPath)"/>
<Target Name="Default">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement" " File="c:\build\test.csproj" XPath="/Project/PropertyGroup[1]/ApplicationVersion" />
</Target>
</Project>
Wheras these dont do anything !
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://mynamespace">
<PropertyGroup>
<ApplicationVersion>5.1.500.16</ApplicationVersion>
</PropertyGroup>
<PropertyGroup>
<ApplicationVersion>old</ApplicationVersion>
</PropertyGroup>
</Project>
and
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TPath>C:\Program Files\MSBuild\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks</TPath>
<AssemblyVersion>5.1.500.18</AssemblyVersion>
</PropertyGroup>
<Import Project="$(TPath)"/>
<ItemGroup>
<Namespaces Include="Mynamespace">
<Prefix>me</Prefix>
<Uri>"http://mynamespace"</Uri>
</Namespaces>
</ItemGroup>
<Target Name="Default">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement" Namespaces="#(Namespaces)" File="c:\build\test.csproj" XPath="//me:Project/PropertyGroup[1]/ApplicationVersion" />
</Target>
</Project>
So what's the deal ? what am i missing ? Is it the formatting of the XPath in the second instance ? I've tried all kinds of variations.
Try this:
<Target Name="Default">
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="RemoveElement" Namespaces="#(Namespaces)" File="c:\build\test.csproj" XPath="//me:Project/me:PropertyGroup[1]/me:ApplicationVersion" />
</Target>
(namespace prefix before each xpath element)
In addition to the advice given in the other answer, remove the quotes from the Uri metadata in the Namespace item.
Note that according to the note for the prefix parameter in the MSDN documentation, specifing the empty string for the Prefix metadata will never work.

copying a jar file in Apache Ant

I need to copy a jar file from one directory to another when my project is built. Placing the statement:
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>
works fine when the project is built alone, but if I clean and build the project I get a warning informing me that the ${test.dir}/ directory hasn't been created yet. If I'm understanding properly I should be able to create a 'target' and specify a dependency for this operation but I'm unsure of what dependency to specify. What series of statements do I need to use to ensure this copy will occur whether I clean and build or just build the project?
Please let me know if any further clarification is needed.
FYI I am using Netbeans 6.8 to build my project.
Assuming you have build, dist and javadoc folders do this in the clean.
<!-- Remove all output generated from this build script -->
<target name="clean" description="Clean project">
<delete dir="${build}" />
<delete dir="${dist}" />
<delete dir="${javadoc}" />
</target>
<!-- Initialize all elements needed for the Build -->
<target name="init">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the build directory structure used by compile
and copy the deployment descriptors into it-->
<mkdir dir="${build}/classes" />
<mkdir dir="${dist}" />
<mkdir dir="${javadoc}" />
</target>
<!-- Write a target such as this -->
<target name="docopy" depends="init" description="do the copy">
<copy file="${test.dir}/MyFirstTest.jar" todir="${dist}"/>
</target>
When you run ant docopy It will run init first and then the docopy task.
You can create other tasks that have a depends="docopy" in it or move the copy file task to the init itself.
If I'm understanding properly I should be able to create a 'target' and specify a dependency for this operation but I'm unsure of what dependency to specify.
Well, either add a dependency to the target that actually creates ${share.path} if that makes sense or introduce a new target to create the directory if it doesn't exists. This is typically done is some kind of init target. Then, add the dependency like this:
<target name="copy-jar" depends="target-a, target-b">
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>
</target>
You could also simply try to create the directory before to copy the library:
<mkdir dir="${share.path}" failonerror="false">
<copy file="${test.dir}/MyFirstTest.jar" todir="${share.path}"/>