CodedUI TestCaseFilter - filter

I'm using a CSV file as a DataSource in my CodedUI tests. The file looks like so:
Environment,URL
Live,www.example.com
Stage,stage.example.com
Test,test.example.com
I'd like to be able to setup my TestCaseFilter to selectively run the tests on only one of the environments when running the vstest.console.exe commandline. I can't seem to find any way to do that, i.e. it looks like the TestCaseFilter commandline parameter only supports specific properties. Am I wrong? Is there a way to pass a custom property to TestCaseFilter so that only the tests that pertain to a specific DataRow are executed?
The DataSource in my tests is setup like so:
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\environments.csv", "environments#csv", DataAccessMethod.Sequential)]
And I am referencing the environment in each test like so:
var url = TestContext.DataRow["URL"].ToString();
Thanks for any insight.

The simple and best way is to add another column next to the environment column in your testdata file. Say the column name is RunStatus. The values should either be 'Yes' or 'No', the logic is that the URL which has Runstatus as Yes should be included for the execution.
Before the TestMethod, have a condition to check the Runstatus of the row is Yes. If it's Yes, then Run the TestMethod.
[TestMethod]
public void RunTheTest(TestContext testcontext)
{
if(testcontext.DataRow["RunStatus"].ToString()=="Yes")
{
TestMethod1();
}
}
Hope it helps. Good luck !!

Related

Refering to a specific page in Wicket i18n properties file

I am building my first ever Wicket project and I find that the amount of properties files in my code base is growing rapidly. Ideally I would like to contain all internationalization in a single file for each language/region. Just so I can find things easily.
I found out that my application properties file could be ideal for this. My application properties file is called ApiAdminApplication.properties. Now I am trying to add my translatables to this file, without making a mess of things.
According to the javadoc of ComponentStringResourceLoader this should be possible. Apparently the lookup order is as follows:
page1.properties => form1.input1.Required
page1.properties => Required
form1.properties => input1.Required
form1.properties => Required
input1.properties => Required
myApplication.properties => page1.form1.input1.Required
myApplication.properties => Required
The second to last line contains the behavior I am looking for, but cannot get to work.
I have a page called CustomerEditPage which in turn contains a form with id customerForm
So here is what I am adding to ApiAdminApplication.properties, and what I think should work according to the snippet above:
CustomerEditPage.customerForm.name=Customer name
Sadly, this does not work. I can however get this to work by leaving out the page name, and starting with customerForm, but that is not what I want. I want per page internationalization contained in a single file.
Can anyone give me some pointers on this? Thanks.
I think the javadoc of ComponentStringResourceLoader is just wrong and should be fixed.
To accomplish what you need you will need to extend ClassStringResourceLoader and override getResourcePath(). In your impl you will have to prepend the result with the name of the page that owns the Component passed as a parameter.
Then you will need to register your loader at ApiAdminApplication#init() method with:
getResourceSettings().getStringResourceLoaders().add(new MyClassStringResourceLoader(ApiAdminApplication.class))
see the defaults.
Please file a bug report at https://issues.apache.org/jira/projects/WICKET/issues so that the javadoc issue is fixed (or someone else who knows better than me how to accomplish this can explain us).
After reporting the bug I ended up doing what martin-g suggested, and extended ClassStringResourceLoader. For your convenience, here is what I did:
public class PrefixedStringResourceLoader extends ClassStringResourceLoader {
public PrefixedStringResourceLoader(Class<?> clazz) {
super(clazz);
}
protected String getResourcePath(final Component component) {
final Class<? extends Page> parentClass = component.getPage().getClass();
final String resPath = super.getResourcePath(component);
if (!resPath.isEmpty())
return String.format("%s.%s", parentClass.getSimpleName(), resPath);
return parentClass.getSimpleName();
}
}
There is a small gotcha to this. It always requires you to work with complete resource paths. This can be a bit tricky, I had some problems with the snippet below:
<input type="submit" wicket:id="save" wicket:message="value:save" />
This evaluated to CustomerEditPage.customerForm.save.save, where I expected it to become: CustomerEditPage.customerForm.save. This is not the case because the wicket:message actually becomes a child of the save form input.
I ended up going for:
<input type="submit" wicket:id="save" wicket:message="value:caption" />
Which evaluates to CustomerEditPage.customerForm.save.caption, which I find somewhat more readable. Of course, you could roll your own more advanced resource loader, but this one is good enough for me.

Run multiple test same build from different tests project

Need your help in the following scenario:
I have a solution with 2 projects with different unit tests
Those projects generate 2 different dll: *deployment.dll and *database.dll
I have a build on TFS that I want to use to run those tests, I'm using "Test Case Filter" to filter the categories of my tests
(TestCategory=TEST1|TestCategory=TEST2|TestCategory=TEST3|TestCategory=TEST4)
and in "Test Sources Spec" I'm filtering both dll (*deployment.dll;*database.dll)
*.deployment.dll has TEST2, TEST3, TEST4
*.database.dll has TEST1
This doesn't work, tests of *database.dll does not run. Test selected in Visual Studio Test Runner
Could you please help on that? If I make the build with only 1 dll, for example, *.database.dll, TEST1 runs well.
(UPDATE) SCENARIO 1
Test Case Filter: TestCategory=TEST1|TestCategory=TEST1|TestCategory=TEST2|TestCategory=TEST3|TestCategory=TEST4
Test Sources Spec: *database.dll;*deployment.dll
only runs TEST1
(UPDATE) SCENARIO 2
Test Case Filter: TestCategory=TEST1|TestCategory=TEST1|TestCategory=TEST2|TestCategory=TEST3|TestCategory=TEST4
Test Sources Spec: **\*deployment.dll;*database.dll
only runs TEST2,TEST3,TEST4
(UPDATE) Does not find tests in Database.dll
I've tested in TFS 2015.3, XAML build, but couldn't reproduce your issue. I'd like to share my steps here for your reference:
I have a solution with some projects, 2 of them are UnitTest projects (UnitTestProject1, UnitTestProject2).
In UnitTest1 project, I added TestCategory for two test case, check screenshot below:
[TestMethod()]
[TestCategory("Pro")]
public void M1Test()
{
//
}
[TestMethod()]
[TestCategory("Dev")]
public void M2Test()
{
//
}
Similar to Step2, in UnitTest2 project, I added TestCategory for two test case, check screenshot below:
[TestMethod()]
[TestCategory("Pro1")]
public void M3Test()
{
//
}
[TestMethod()]
[TestCategory("Dev1")]
public void M4Test()
{
//
}
Edit "Test Case Filter" and "Test Sources Spec" in build definition like below screenshot and queue a build:
The test result is as expected. Only M1Test and M2Test in UnitTestProject1, M3Test and M4Test in UnitTestProject2 are tested.
Finally, it's solved :)
So, what I have done to solve this problem, was, change Build Process Template.
There are one step in this process, calling: "FindMatchingFiles"
I change this value as the below image shows. (however, from now on, I must use "**\*" in all my filters that use this process template). This operation make sure that I have the assemblies with fullpath destination complete.
If you have different solutions, please post here :)
Special thank you to #Cece - MSFT for all support

Can I programmatically "emit" test cases with xUnit?

Is it possible to use something other than reflection and the [Fact] attribute on a test method to expose tests to xUnit test runner? For example, I'd like to do something like:
[FactSource] // just making this up
public IEnumerable<ITest> GetUnitTests()
{
yield return new TestCase("test case 1", () => FooAssertion());
yield return new TestCase("test case 2", () => BarAssertion());
}
I've wanted to do this many times to reduce the boilerplate of a function to wrap every single case. Usually it makes sense, but when I am testing 100 API endpoints it's the difference between a file with 100 lines vs. 400 lines of code. Also, I have cases where I want to load the tests from a .JSON or .XML file so it would be great if there was another way to load the tests rather than just [Fact] or [Theory] attributes.
NOTE: [Theory] works great for some tests like this, but it doesn't work for loading the cases from a file or for the case I demonstrate above where I am using lambda expressions.
Thank you!
Check out Exude. It does exactly what you want.

AX2012 - Pre-Processed RecId parameter not found

I made a custom report in AX2012, to replace the WHS Shipping pick list. The custom report is RDP based. I have no trouble running it directly (with the parameters dialog), but when I try to use the controller (WHSPickListShippingController), I get an error saying "Pre-Processed RecId not found. Cannot process report. Indicates a development error."
The error is because in the class SrsReportProviderQueryBuilder (setArgs method), the map variable reportProviderParameters is empty. I have no idea why that is. The code in my Data provider runs okay. Here is my code for running the report :
WHSWorkId id = 'LAM-000052';
WHSPickListShippingController controller;
Args args;
WHSShipmentTable whsShipmentTable;
WHSWorkTable whsWorkTable;
clWHSPickListShippingContract contract; //My custom RDP Contract
whsShipmentTable = WHSShipmentTable::find(whsWorkTable.ShipmentId);
args = new Args(ssrsReportStr(WHSPickListShipping, Report));
args.record(whsShipmentTable);
args.parm(whsShipmentTable.LoadId);
contract = new clWHSPickListShippingContract();
controller = new WHSPickListShippingController();
controller.parmReportName(ssrsReportStr(WHSPickListShipping, Report));
controller.parmShowDialog(false);
controller.parmLoadFromSysLastValue(false);
controller.parmReportContract().parmRdpContract(contract);
controller.parmReportContract().parmRdpName(classStr(clWHSPickListShippingDP));
controller.parmReportContract().parmRdlContract().parmLanguageId(CompanyInfo::languageId());
controller.parmArgs(args);
controller.startOperation();
I don't know if I'm clear enough... But I've been looking for a fix for hours without success, so I thought I'd ask here. Is there a reason why this variable (which comes from the method parameter AifQueryBuilderArgs) would be empty?
I'm thinking your issue is with these lines (try removing):
controller.parmReportContract().parmRdpContract(contract);
controller.parmReportContract().parmRdpName(classStr(clWHSPickListShippingDP));
controller.parmReportContract().parmRdlContract().parmLanguageId(CompanyInfo::languageId());
The style I'd expect to see with your contract would be like this:
controller = new WHSPickListShippingController();
contract = controller.getDataContractObject();
contract.parmWhatever('ParametersHere');
controller.parmArgs(args);
And for the DataProvider clWHSPickListShippingDP, usually if a report is using a DataProvider, you don't manually set it, but the DP extends SRSReportDataProviderBase and has an attribute SRSReportParameterAttribute(...) decorating the class declaration in this style:
[SRSReportParameterAttribute(classstr(MyCustomContract))]
class MyCustomDP extends SRSReportDataProviderBase
{
// Vars
}
You are using controller.parmReportContract().parmRdpContract(contract); wrong, as this is more for run-time modifications. It's typically used for accessing the contract for preRunModifyContract overloads.
Build your CrossReference in a development environment then right click on \Classes\SrsReportDataContract\parmRdpContract and click Add-Ins>Cross-reference>Used By to see how that is generally used.
Ok, so now I feel very stupid for spending so much time on that error, when it's such a tiny thing...
The erronous line is that one :
controller.parmReportName(ssrsReportStr(WHSPickListShipping, Report));
Because WHSPickListShipping is the name of the AX report, but I renamed my custom report clWHSPickListShipping. What confused me was that my DataProvider class was executing as wanted.

Unitils and DBMaintainer - how to make them work with multiple users/schemas?

I am working on a new Oracle ADF project, that is using Oragle 10g Database, and I am using Unitils and DBMaintainer in our project for:
updating the db structure
unittesting
read in seed data
read in test data
List item
In our project, we have 2 schemas, and 2 db users that have privilegies to connect to these schemas. I have them in a folder structure with incremental names and I am using the #convention for script naming.
001_#schemaA_name.sql
002_#schemaB_name.sql
003_#schemaA_name.sql
This works fine with ant and DBMaintainer update task, and I supply the multiple user names by configuring extra elements for the ant task.
<target name="create" depends="users-drop, users-create" description="This tasks ... ">
<updateDatabase scriptLocations="${dbscript.maintainer.dir}" autoCreateDbMaintainScriptsTable="true">
<database name="${db.user.dans}" driverClassName="${driver}" userName="${db.user.dans}" password="${db.user.dans.pwd}" url="${db.url.full}" schemaNames="${db.user.dans}" />
<database name="idp" driverClassName="${driver}" userName="${db.user.idp}"
password="${db.user.idp.pwd}" url="${db.url.full}" schemaNames="${db.user.idp}" />
</updateDatabase>
</target>
However, I cant figure out, how to make the DBMaintainer update task create the xsd schemas from my db schemas?
So, I decided to use Unitils, since its update creates xsd schemas.
I haven't found any description or documentation for the Unitils ant tasks - can anyone give some hints?
For the time being I have figured out to run Unitils by creating a Junit test, with #Dataset annotation. I can make it work with one schema, and one db user. But I am out of ideas how to make it work with multiple users?
Here is the unitils-local.properties setup I have:
database.url=jdbc\:oracle\:thin\:#localhost\:1521\:vipu
database.schemaNames=a,b
database.userName=a
database.password=a1
Can any of you guys give me a tip, how to make Unitils work with the second user/schema ??
I will be extremely gratefull for your help!
eventually I found a way to inject any unitil.properties of your choice --- by instantiating Unitils yourself!
You need a method that is evoked #BeforeClass, in which you perform something like the following:
#BeforeClass
public void initializeUnitils {
Properties properties;
...
// load properties file/values depending on various conditions
...
Unitils unitils = new Unitils();
unitils.init(properties);
Unitils.setInstance( unitils );
}
I choose the properties file depending on which hibernate configuration is loaded (via #HibernateSessionFactory), but there should be other options as well
I have figure out how to make dbmaintain and unitils work together on multi-database-user support, but the solution is a pure ant hack.
I have set up the configuration for dbmaintain, using multi-database-user support.
I have made a unitils-local.properties file with token keys for replacement.
The init target of my ant script is generating a new unitils-local.properties file, by replacing tokens for username/password/schema with values that are correct for the target envirnonment, and then copies it to the users home directory.
I have sorted the tests into folders, that are prefixed with the schema name
When unitils is invoked, it picks up the unitils-local.properties file just created by the ant script, and does its magic.
Its far from pretty, but it works.
Check out this link: http://www.dbmaintain.org/tutorial.html#From_Java_code
Specifically you may need to do something like:
databases.names=admin,user,read
database.driverClassName=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin://mydb:1521:MYDB
database.admin.username=admin
database.admin.password=adminpwd
database.admin.schemaNames=admin
database.user.userName=user
database.user.password=userpwd
database.user.schemaNames=user
database.read.userName=read
database.read.password=readpwd
database.read.schemaNames=read
Also this link may be helpful: http://www.dbmaintain.org/tutorial.html#Multi-database__user_support
I followed Ryan suggestion. I noticed couple changes when I debugged UnitilsDB.
Following is my running unitils-local.properties:
database.names=db1,db2
database.driverClassName.db1=oracle.jdbc.driver.OracleDriver
database.url.db1=jdbc:oracle:thin:#db1d.company.com:123:db1d
database.userName.db1=user
database.password.db1=password
database.dialect.db1=oracle
database.schemaNames.db1=user_admin
database.driverClassName.db2=oracle.jdbc.driver.OracleDriver
database.url.db2=jdbc:oracle:thin:#db2s.company.com:456:db2s
database.userName.db2=user
database.password.db2=password
database.dialect.db2=oracle
Make sure to use #ConfigurationProperties(prefix = "database.db1") to connecto to particular database in your test case:
#RunWith(UnitilsJUnit4TestClassRunner.class)
#ConfigurationProperties(prefix = "database.db1")
#Transactional
#DataSet
public class MyDAOTest {
..
}

Resources