I have a number of unit tests in VSCode which I want to debug. The problem is I want to debug only one unit test. By default VS Code runs all the unit tests. I want to specify only one unit test to run like in Visual Studio. Is there any way to do this?
According to the unit test framework you are using you should be able to create a config.json or something similar where you can set options for your tests. Within this config you should be able to specify the path of all unit tests that shall be executed. For example when you are running javaScript unit tests with jasmine you can set something like this in your config.json:
"spec_dir": "./out/test/unittest",
"spec_files": [
"**/*[tT]est.js"
]
Here you can check out how this behavior is done with mocha. To run only one unit test you just set an absolute path. For example
"spec_files": [
"./path/to/a/single/unittest.js"
]
Related
I am writing unit tests for my React JS components in a specific folder using Jest testing framework. All my components are within, let's say, "src/components" folder. I can get the coverage of each test adding "--coverage" flag when I run the command as follow.
jest --watchAll --coverage
It's going to generate the report in the coverage folder and I can view the code coverage of each tests as follow.
That is going to display the code coverage of each component that is included in the tests. But how can I see the list of components that are not yet covered in the tests (maybe the list of components that are not yet covered in the tests within a specific folder). Is it possible to get the stats for that in percentage too? How can I do that? Is it possible?
Add the collectCoverageFrom paths to your extra folders, using the glob pattern. For instance, I have:
collectCoverage: true,
collectCoverageFrom: [
'<rootDir>/**/*.ts',
'!<rootDir>/**/*.interface.ts',
'!<rootDir>/**/*.mock.ts',
'!<rootDir>/**/*.module.ts',
'!<rootDir>/**/__mock__/*',
'!<rootDir>/src/main.ts'
],
I have created a TFS2013 Build Definition using the template TfvcTemplate.12.xaml
I have specified a test run using VSTestRunner and enabled code coverage.
I am integrating this build with sonar analysis by specifying pre-build and post-test execution script.
Prebuild script arguments: begin /name:PrjName /key:PrjKey /version:1.0 /d:sonar.cs.vstest.reportsPaths="tst*.trx"
I have the "Unit Test Coverage" widget on my sonar dashboard.
It shows Unit Test Coverage %
However, it does not show the unit tests (ie how many tests were run, how many failed ,etc).
I looked in the build output. There is a "tst" folder, however it is empty.
I cannot find the trx files.
I believe that either the trx files are not properly generated or
I am not setting the "sonar.cs.vstest.reportsPaths" correctly.
Please help !!
Relative paths are not well supported: Specify an absolute path wildcard to your *.trx reports. See https://jira.sonarsource.com/browse/SONARMSBRU-100 for details on the bug.
Note that you probably can use the TFS 2013 environment variables to construct this absolute path wildcard: https://msdn.microsoft.com/en-us/library/hh850448.aspx#env_vars
I'm trying to use test support classes within my tests. I want these classes to be available for all different test types.
My directory structure is as follows;
/test/functional
/test/integration
/test/unit
/test/support
I have test helper classes within the /test/support folder that I would like to be available to each of the different test types.
I'm using GGTS and I've added the support folder to the classpath. But whenever I run my integration tests running 'test-app' I get a compiler 'unable to resolve class mypackage.support.MyClass
When I run my unit tests from within GGTS the support classes are found and used. I presume this is because the integration tests run my app in its own JVM.
Is there any way of telling grails to include my support package when running any of my tests?
I don't want my test support classes to be in my application source folders.
The reason that it works for your unit tests inside the IDE is that all source folders get compiled into one directory, and that is added to your classpath along with the jars GGTS picks up from the project dependencies. This is convenient but misleading, because it doesn't take into account that Grails uses different classpaths for run-app and each of the test phases, which you see when you run the integration tests. GGTS doesn't really run the tests; it runs the same grails test-app process that you do from the commandline, and captures its output and listens for build events so it can update its JUnit view.
It's possible to add extra jar files to the classpath for tests because you can hook into an Ant event and add it to the classpath before the tests start. But the compilation process is a lot more involved and it looks like it would be rather ugly/hackish to get it working, and would likely be brittle and stop working in the future when the Grails implementation changes.
Here are some specifics about why it'd be non-trivial. I was hoping that you could call GrailsProjectTestCompiler.compileTests() for your extra directory, but you need to compile it along with the test/unit directory for unit tests and the test/integration directory for integration tests, and the compiler (GrailsProjectTestCompiler) presumes that each test phase only needs to compile that one directory. That compiler uses Gant, and each test phase has its own Grailsc subclass (org.grails.test.compiler.GrailsTestCompiler and org.grails.test.compiler.GrailsIntegrationTestCompiler) registered as taskdefs. So it should be possible to subclass them and add logic to compile both the standard directory and the shared directory, and register those as replacements, but that requires also subclassing and reworking GrailsProjectTestRunner (which instantiates GrailsProjectTestCompiler), and hooking into an event to replace the projectTestRunner field in _GrailsTest.groovy with your custom one, and at this point my brain hurts and I don't want to think about this anymore :)
So instead of all this, I'd put the code in src/groovy and src/java, but in test-specific packages that make it easy to exclude the compiled classes from your WAR files. You can do that with a grails.war.resources closure in BuildConfig.groovy, e.g.
grails.war.resources = { stagingDir ->
println '\nDeleting test classes\n'
delete(verbose: true) {
// adjust as needed to only delete test-specific classes
fileset dir: stagingDir, includes: '**/test/**/*.class'
}
println '\nFinished deleting test classes\n'
}
We have created a build definition in TFS 2013 that runs unit tests and then calls a PowerShell script once completed.
What we would like is the ability to pass the results of the unit test (passed/failed) to the PowerShell script so that a check can be done to verify if the unit tests passed.
Is there a parameter that can be used in the 'Post-test script path' setting or a possible workaround?
You should be able to use the predefined variable/property combo BuildDetail.TestStatus.
I don't have Unit Test script yet. I just want to see that the the integration itself is working and show 'Passed' results, is it possible without set of unit test? Currently, I always get Failed status on Summary of Results.
When creating the bot you can uncheck "Perform Test Action" and the bot will not run any unit tests. If you already created the bot you can go the bot under Log Navigator, select it and choose Edit Bot. You will be able to do the same thing there.
Although you haven't created unit tests yourself they are probably already in the project.
If you created your test project from one of the project templates, unit tests are included by default.
The unit tests included by default have a single test that always fails. Locate the unit test and comment out the XCTFail line in the [your project name]Tests.m file
//XCTFail(#"No implementation for \"%s\"", __PRETTY_FUNCTION__);