When should I rewrite my dll when using coyote to write unit test? - coyote

I am trying to write some unite tests based on coyote.
I found that in the tutorial I should rewrite my assembly before coyote test command.
However, when integrate coyote tests into unit test platform using TestingEngine, it explored bugs without doing any rewriting manually.
Did I doing the right thing? If I can explore the bug without rewriting assembly, what the operate exactly works for?
Thank you!

In that case, the easiest option is to rewrite during your build.
Add the following to .csproj.
<ItemGroup>
<None Update="rewrite.coyote.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="CoyoteRewrite" AfterTargets="AfterBuild">
<Exec Command="dotnet tool run coyote rewrite$(OutputPath)/rewrite.coyote.json -v info" />
</Target>
You have to put your rewrite.coyote.json in your project's root folder (next to your .csproj and set the AssembliesPath to ..
My rewrite.coyote.json looks like:
{
"AssembliesPath": ".",
"Assemblies": [
"MySut.dll",
"MySut.UnitTests.dll",
"MySut.Coyote.dll"
],
"IsRewritingConcurrentCollections": "false"
}

Related

How to use .net 6 with MySQL

Create a project in Visual Studio.
Open Program.cs
Replace:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connectionString));
For:
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(connectionString, new MySqlServerVersion(new Version(5, 7))));
Visual Studio will advertise you for an error.
Accept the suggestion and install package "Pomelo..."
Open appsettings.json and replace the SqlServer DefaultConnection with your MySQL values.
Something like:
"DefaultConnection": "server=your.server.com;user=your_user;password=your_pw;database=your_dbname;port=3306"
remove-migration (all of them)
add-migration
update-database
Done
Everything else works like the same.
Make sure you are using
<PackageReference Include="MySql.EntityFrameworkCore" Version="6.0.4" />
see:
https://www.nuget.org/packages/MySql.EntityFrameworkCore/6.0.4#dependencies-body-tab
(to make it clear, make sure you are NOT using the below (similarly named, but abandoned)
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.22" />
See
https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/
2.
Consider a change (which is my personal preference between the two)
https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql
Bonus tip:
When "fishing" at nuget.org .. always look at the "Dependencies" and "Frameworks" ("tabs" on the gui of nuget page)....
https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql#dependencies-body-tab
Bonus Tip #2.
Always post your csproj contents with dependency questions. At least the germane portions of your csproj files.
Extra:
See my answer here:
Cannot find the UseMysql method on DbContextOptions
There are "cAsE iSsuEs" with the MySql/MYSQL using statements to watch carefully.

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.

CruiseControl unable to recognize modifications for Mercurial repository

I am trying to implement a continuous build stack, and decided to use CruiseControl with Ant. However, it seems that CruiseControl is having problem picking up the changes from my Mercurial directory. Here's some code from config.xml with a bunch of unnecessary elements taken out. One workaround I found was to set requiremodification to false, which will build the software regardless of the changes made. Am I missing something here? Or is this a bug of CruiseControl.
<!--config.xml-->
<project name="test_runner" buildafterfailed="false"
requiremodification="true" forceonly="${test_runner.inactive}">
<listeners>
<currentbuildstatuslistener file="${projectLogsDir}/status.txt" />
</listeners>
<bootstrappers>
</bootstrappers>
<modificationset quietperiod="${quietPeriod}">
<mercurial localworkingcopy="${mercurialDir}/solution1" property="solution1_changed" />
</modificationset>
<schedule interval="${scheduleInterval}">
<ant liveOutput="true" />
</schedule>
</project>
In CruiseControl.Net the server logs which command it performs to check for changes. You can check if this command is correct by running it yourself on the command line. I had the same issue with Perforce, and by running the command myself I found out that I had configured an incorrect view.
Note that I'm much more familiar with CruiseControl.Net than CruiseControl, so this might not apply to CruiseControl.

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}"/>

FitNesse configuration files

I'm using FitNesse as a functional testing framework. I'm running into trouble when FitNesse runs code that needs configuration.
If I need to get a connection string from the configuration file, I can get it to work by adding it to the FitServer.exe.config. However, I don't like that solution. I would like FitNesse to load my own configuration file, namely TheNameOfMyApp.dll.config.
Is this possible?
Sure, easy to do. I'm assuming you're using the dotnet or dotnet2 test runner. I'm using the dotnet2 test runner, and here's how I've got it set up:
First, when you !define your COMMAND_PATTERN, include -c suite.config. For instance, I have the following in root:
!define COMMAND_PATTERN {%m -c suite.config %p}
!define TEST_RUNNER {..\..\bin\Debug\FitServer.exe}
suite.config goes in the same dir as fitnesse.jar:
<suiteConfig>
<fit.Settings>
<appConfigFile>..\..\MyProjectFolder\fitnesse\MyProjectName.config</appConfigFile>
</fit.Settings>
<fit.Assemblies>
</fit.Assemblies>
<fit.FileExclusions>
<add>^\.svn$</add>
</fit.FileExclusions>
<fit.Namespaces>
</fit.Namespaces>
<fit.CellHandlers>
</fit.CellHandlers>
<fitlibrary.CellHandlers>
</fitlibrary.CellHandlers>
</suiteConfig>
MyProjectName.config looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="keyname" value="something" />
</appSettings>
</configuration>
You can make things easier for yourself if you use an absolute path for the appConfigFile. I started off with an absolute path, got things working, then switched to a relative path by trial and error.
Note that I'm running my test runner from a non-standard location, which will affect the relative path in suite.config. The path is relative to your TEST_RUNNER location, NOT to suite.config or fitnesse.jar.
yes it is possible but an awful load of work. you need to define a test-project where you have your tests in it and a "wrapper"-project where you have the functionality of providing the tests with data and configuration settings.