orderedtests not working with vstest.console.exe when .runsettings file is specified - MS Test - vstest.console.exe

I have the following:
.orderedtest file which has a list of tests in an order
.runsettings file where I have specified some test parameters
I am trying to execute the tests through command line, using the following command:
vstest.console.exe MyOrderedTests.orderedtest /Settings:MyTestParameters.runsettings /TestCaseFilter:"TestCategory=Production" /Logger:trx
I am getting the below warning and none of the tests are executed.
Warning: No test is available in MyOrderedTests.orderedtest. Make sure that installed test discoverers & executors, platform & framework version settings are appropriate and try again.
I really appreciate the help!
I even tried to run tests through the VS IDE. To elaborate more:
1. I have two tests
2. I have a Class Initialize which access the TestRunParameters from a .runsettings file.
3. I print the TestRunParameter in the tests.
4. I execute the tests individually and even all at once, they execute just fine.
Now I introduce the test ordering using .orderedtest file
1. I execute the tests using this orderedtest file and I get the NullReferenceException in the Class Initialize (where it tries to access the TestRunParameters from .runsettings file)
Class Initialization method TestTestProject.UnitTest1.ClassInit threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object..
Below is my simple sample test code:
public static string url;
[TestMethod]
public void TestMethod1()
{
Console.WriteLine("Test Method 1");
Console.WriteLine(url);
}
[TestMethod]
public void TestMethod2()
{
Console.WriteLine("Test Method 2");
Console.WriteLine(url);
}
[ClassInitialize]
public static void ClassInit(TestContext context)
{
url = context.Properties["webAppUrl"].ToString();
}
I get the NullReferenceException in the ClassInit().

Related

testTags() test method not recognized as test in my gradle project, using junit5 [duplicate]

This question already has an answer here:
Unable to use read('classpath:') when running tests with standalone karate.jar
(1 answer)
Closed 2 years ago.
I added below test methods to my runner class. When I try to run the testTags() test, I get 'No tests found for given includes: ....' and 'Test events were not received' (in my IDE) errors. I have ensured that the "#test1" tag is a valid tag in my feature file.
The testFullPath() method runs my entire feature, as expected. But when I try to implement other test methods, they are not recognized.
I'm using karate-junit5:0.9.5.RC5
package WebServices.Regression;
import com.intuit.karate.junit5.Karate;
public class Regression_Runner {
#Karate.Test
Karate testFullPath() {
return new Karate().feature("regressionTest.feature").relativeTo(getClass());
}
#Karate.Test
Karate testTags() {
return new Karate().feature("regressionTest.feature").tags("#test1").relativeTo(getClass());
}
}
There's no need to have everything relativeTo(someClass) just use this form:
return Karate.run("classpath:/some/package/regressionTest.feature")
Else sorry nothing anyone can do, please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
Maybe you are better off using the ZIP release: https://github.com/intuit/karate/wiki/ZIP-Release

How to programatically tell Spring Boot application that application.yml is in app user home directory?

I am attempting to move my application.yml outside of my application to the user directory that the application runs under. I am aware that a common approach is to use startup params at runtime like -Dconfig.location=/path/to/external.properties (which incidentally I can't seem to make work propertly), but I need to be able to do this without changing the startup script if at all possible.
My goal was to do this in the main() method of the application groovy file that starts the app. In that method, I am detecting the user's home directory, and am attempting to set that as a property for the app to use. However, all approaches I have attempted have ended up with a FileNotFound (application.yml). can someone offer any advice on achieving what I want? Below is the most recent attempt
static void main(String[] args) throws NoSuchAlgorithmException, IOException, URISyntaxException {
String configPath = "${System.getProperty('user.home')}"
ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(Angular4SpringbootApplication)
.properties("spring.config.name:application,conf",
"spring.config.location=classpath:$configPath/application.yml")
.build().run(args)
SpringApplication.run(Angular4SpringbootApplication, args)
}
Since you pass the command line parameters to SpringApplication.run you could simply modify them before. I don't know much about Groovy, but I think this should work:
static void main(String[] args) {
SpringApplication.run(Angular4SpringbootApplication, ["--spring.config.location=file:${System.getProperty('user.home')}/application.yml"] + args)
}
You could also set a system property before starting the Spring context:
static void main(String[] args) {
System.setProperty('spring.config.location', "${System.getProperty('user.home')}/application.yml")
SpringApplication.run(Angular4SpringbootApplication, args)
}
If you do not like application.properties as the configuration file
name, you can switch to another file name by specifying a
spring.config.name environment property. You can also refer to an
explicit location by using the spring.config.location environment
property (which is a comma-separated list of directory locations or
file paths). The following example shows how to specify a different
file name:
java -jar myproject.jar --spring.config.name=myproject
Or you can use location (if rour file is outside your app, prefix with file: ) :
java -jar myproject.jar --spring.config.location=classpath:/default.properties
spring.config.name and spring.config.location are used very early to
determine which files have to be loaded, so they must be defined as an
environment property (typically an OS environment variable, a system
property, or a command-line argument).
Edit
If you want to do it without changing the startup script, you can do it like this :
#SpringBootApplication
public class SimpleBoot {
public static void main(String[] args) {
System.setProperty("spring.config.location","file:/path/to/application.yml")
SpringApplication.run(SimpleBoot.class, args);
}
}

Cucumber-cpp step defiinition runner exits immediately

Based on the instructions given at cucumber-cpp github repo and cucumber-cpp step definition quick-start guide , I created my cucumber step definition files. The features and their step_definition files are under features/ folder, and the cpp code is built with cucumber-cpp headers and linked against libcucumber-cpp.a as instructed.
Cucumber step definition runners should stay running as a seperate process and cucumber command should execute while the runner is running. Indeed, the examples in the cucumber-cpp repository execute like that, but when I create my own step definitions, with gtest or boost test, they execute immediately, without waiting for calls from cucumber.
Onats-MacBook-Pro:bin onatbas$ ./tests/AdditionTest_TESTTARGET
Running main() from gtest_main.cc
[==========] Running 0 tests from 0 test cases.
[==========] 0 tests from 0 test cases ran. (0 ms total)
[ PASSED ] 0 tests.
Onats-MacBook-Pro:bin onatbas$
Instead of executing immediately, it should say nothing and wait for cucumber calls. I copy-pasted the example code from the cucumber-cpp into my project and they, too, exit immediately. So even though there's no source code difference between cucumber-cpp's examples and mine, they act differently.
I suspected the cmake build scripts might be linking with different libraries, but the linkage process is exactly the same too.
Does anybody have any idea on why this might be happening?
Here's the repository with minimum code that reproduces the error I have. https://github.com/onatbas/CucumberCppTest
The complete trace is at readme.
The cucumber files are under features/, and ther's only one feature that's identical to what's here
The runner executable is defined in tests/CMakeLists.txt
For quick reference: Here's the step-definition file
AdditionTest.cxx
#include <boost/test/unit_test.hpp>
#include <cucumber-cpp/defs.hpp>
#include <CucumberApp.hxx>
using cucumber::ScenarioScope;
struct CalcCtx {
Calculator calc;
double result;
};
GIVEN("^I have entered (\\d+) into the calculator$") {
REGEX_PARAM(double, n);
ScenarioScope<CalcCtx> context;
context->calc.push(n);
}
WHEN("^I press add") {
ScenarioScope<CalcCtx> context;
context->result = context->calc.add();
}
WHEN("^I press divide") {
ScenarioScope<CalcCtx> context;
context->result = context->calc.divide();
}
THEN("^the result should be (.*) on the screen$") {
REGEX_PARAM(double, expected);
ScenarioScope<CalcCtx> context;
BOOST_CHECK_EQUAL(expected, context->result);
}
and here's the tests/CMakeLists.txt file where the executable is added.
cmake_minimum_required(VERSION 3.1)
find_package(Threads)
set(CUCUMBERTEST_TEST_DEPENDENCIES cucumberTest
${CMAKE_THREAD_LIBS_INIT}
${GTEST_BOTH_LIBRARIES}
${GMOCK_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES}
${CUCUMBER_BINARIES}
)
macro(ADD_NEW_CUCUMBER_TEST TEST_SOURCE FOLDER_NAME)
set (TARGET_NAME ${TEST_SOURCE}_TESTTARGET)
add_executable(${TARGET_NAME} ${CMAKE_SOURCE_DIR}/features/step_definitions/${TEST_SOURCE})
target_link_libraries(${TARGET_NAME} ${CUCUMBERTEST_TEST_DEPENDENCIES})
add_test(NAME ${TEST_SOURCE} COMMAND ${TARGET_NAME})
set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER ${FOLDER_NAME})
endmacro()
ADD_NEW_CUCUMBER_TEST(AdditionTest "cucumberTest_tests")
Your example outputs
Running main() from gtest_main.cc
That main method will run the test runner's default behaviour instead of Cucumber-CPP's. The main mathod that you want (src/main.cpp) is included as part of the compiled cucumber-cpp library.
Try moving ${CUCUMBER_BINARIES} in CUCUMBERTEST_TEST_DEPENDENCIES before all others, or linking to testing libraries that do not contain a main method (e.g. GoogleTest ships with two libraries: one with and one without the main method).

Grails test-app updating function being tested and test print out problems

I am running grails 2.3.3 in a GGTS.
I am successfully running a single unit test for a service function within the Spring GGTS.
I am hoping to be able to use this unit test to develop the particular function - such an approach will really speed up my development going forward.
This means I need to make changes to the service function that is being tested and then retest over and over again (no doubt a sad reflection on my coding skills!). The problem is when I make a change to the logic or any log.debug output it does not come through in the test. In other words the test continues to run against the original service function and not the updated one.
In order for me to force it to use the updated function the only way I have found that will do this is to restart the GGTS!
Is there a command I can use in GGTS to force a test on the most recent version of the function I am testing?
Here are the commands I am using within the GTTS:
test-app unit: UtilsService
I do run a clean after a function update without any success:
test-app -clean
I am also struggling with getting additional output from within the test function - introducing 'println' or 'log.debug' commands results in a failure of the test.
It would be useful to know of a good link to documentation about the test syntax - I have looked at grails section 12 about testing in general.
Here is the test file:
package homevu1
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {#link grails.test.mixin.services.ServiceUnitTestMixin} for usage instructions
*/
#TestFor(UtilsService)
class UtilsServiceSpec extends Specification {
// to test utilSumTimes for example use the command :
// test-app utilSumTimes
// test-app HotelStay
def setup() {
}
def cleanup() {
}
void "test something"() {
when:
def currSec = service.utilSumTimeSecs( 27, 1, false)
//println "currSec" , currSec
then:
//println "currSec" , currSec
assert currSec == "26"
}
}
If I uncomment either of the println lines these comments are not displayed and the test fails.
Welcome any suggestions.
-mike
I've to get this working now by running grail from a command prompt (in MS Windows).
In the command prompt I moved to the root folder/directory of the grails project - in my case:
cd C:\grails\workspace\rel_3.1.0\HomeVu
Then I type grails to start a grails command line session.
The unit test command I used being:
test-app -unit UtilsService -echoOut -echoErr
That said I still am unable to successfully put any print commands in the test file - but I can use the assert to determine any problems.
Also output from the last log.debug line of the grails code of the service function fails to appears. Perhaps there is some output buffering issue with MS Windows here.
At least I can now do some rapid function development, by making changes to the service/function code and instantly test is against a set of known requirement conditions.
Hope this helps others.
-mike

self hosted vnext application

I was wondering if I could refactor a self-hosted app (console app that starts and displays the URL of the webservices it provides) for it to work on pure vnext instead of owin.
The owin code is the following
namespace Selfhostingtest
{
class Program
{
static void Main(string[] args)
{
String strHostName = string.Empty;
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
var options = new StartOptions();
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
if (!addr[i].IsIPv6LinkLocal && addr[i].AddressFamily == AddressFamily.InterNetwork)
{
Console.WriteLine("IPv4 Address {0}: {1} ", i, addr[i].ToString());
options.Urls.Add(String.Format("http://{0}:5000/", addr[i].ToString()));
}
}
using (WebApp.Start<Startup>(options))
{
Console.WriteLine("Razor server is running. Press enter to shut down...");
Console.ReadLine();
}
}
}
}
For the record, I don't want to use the "k web" command line start. I want to fully package the vnext app as an executable file.
Instead of Microsoft.Owin.Hosting, the Microsoft.AspNet.Hosting should be used (same class as in the "k web" command definition. Keep in mind that Owin Startup expects IAppBuilder and the vnext expects IBuilder.
In ASP.NET vNext you cannot build an EXE file, but you can definitely package up an app to be self-contained. Check out the kpm pack command that you can run in your app's folder. It will package up all the dependencies as well as generate the command scripts that you can use (instead of using k web etc.). Ultimately if you look at what k web does, it's just some shell scripts that end up running klr.exe with various parameters to indicate what it should start.
The project wiki has some basic information on the kpm tool's various options: https://github.com/aspnet/Home/wiki/Package-Manager
Here is the command line help for kpm pack to give you an idea of what it can do.
Usage: kpm pack [arguments] [options]
Arguments:
[project] Path to project, default is current directory
Options:
-o|--out <PATH> Where does it go
--configuration <CONFIGURATION> The configuration to use for deployment
--overwrite Remove existing files in target folders
--no-source Don't include sources of project dependencies
--runtime <KRE> Names or paths to KRE files to include
--appfolder <NAME> Determine the name of the application primary folder
-?|-h|--help Show help information

Resources