Android Studio Start all unit tests, not instrumented - android-studio

So far I've got bunch of tests in my multi module project. All of them could be run on PC... except one. It's intrumented test for Room DAO class. There is no problem if I launch it separately on emulator.
But if I launch all the unit tests on PC, this one starts too. And of course it failed as there is no runner for it here.
Why did it even started? I thought instrumented tests shouldn't start with unit ones. And yes, it's placed in androidTest.
My build config could be helpful also.
So the question is: how to start only tests for launch on PC? And vice versa: how to start only tests for device/emulator? Next step is to write and launch them too.
Update
I've tried using gradle run xml:
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Unit tests" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="--tests "*"" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="cleanTestDebugUnitTest" />
<option value="testDebugUnitTest" />
</list>
</option>
<option name="vmOptions" value="" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<method v="2" />
</configuration>
</component>
It doesn't run android test, but also skips tests from koltin modules (without android dependencies). Worked partially.

Related

Is there a way to use mps-extensions via Gradle?

I see https://github.com/JetBrains/MPS-extensions publishes releases via GitHub, however it does not look convenient for integration of the artifacts to a MPS-based project.
What if my project is built via MPS and it depends on MPS-extensions? It would be great if there was a way to automatically download proper extensions artifact via command line (e.g. ./gradlew downloadExtensions)
The following worked for me:
build.gradle (see https://github.com/Hardella/ide61131/blob/8088fbd9bcc2780f5772856a962fbfe6954b3e50/build.gradle ):
repositories {
maven { url 'https://projects.itemis.de/nexus/content/repositories/mbeddr' }
mavenCentral()
}
configurations {
mpsExtensions
}
dependencies {
mpsExtensions "de.itemis.mps:extensions:2018.2.+"
}
task resolve_extensions(type: Copy) {
dependsOn configurations.mpsExtensions
from {
configurations.mpsExtensions.resolve().collect { zipTree(it) }
}
into "lib"
}
Then ./gradlew resolve_extensions downloads and unpacks mps-extensions into lib/de.itemis.mps.extensions/... folder.
Then it can be plugged to MPS instance via Preferences -> Build, Execution, Deployment -> Project Libraries / Global Libraries.
The following .mps/libraries.xml configures the library as Project Library:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLibraryManager">
<option name="libraries">
<map>
<entry key="mps-extensions">
<value>
<Library>
<option name="name" value="mps-extensions" />
<option name="path" value="$PROJECT_DIR$/lib/de.itemis.mps.extensions" />
</Library>
</value>
</entry>
</map>
</option>
</component>
</project>

How to integrate xUnit.net with CruiseControl.net

I have a continuous integration server that discovers and runs assemblies with NUnit tests. I would like to add some assemblies with xUnit.net tests to the mix. How would I do that?
Download xunit-build-xyzw.zip from xUnit.net on CodePlex and extract it to, for example, C:\Program Files\xUnit.net. Add this location to PATH environment variable
be sure to have no trailing semicolon
Modify your CC.NET *.build script to discover assemblies by convention, as outlined below
note that command line argument syntax no longer has equals sign
In C:\Program Files\CruiseControl.NET\server\ccnet.config, Merge XML files produced by NUnit runner and by xUnit.net runner, as outlined below
merging happens after build, irrespective of build status
be sure results of test run get deleted in the beginning of build script
Restart CC.NET
Download xUnitSummary.xsl from xUnit.net on GitHub and place it in C:\Program Files (x86)\CruiseControl.NET\WebDashboard\xsl
In C:\Program Files\CruiseControl.NET\WebDashboard\dashboard.config, modify buildPlugins element as outlined below
Restart IIS
Additional info:
CruiseControl.Net – Server Installation at Neal's Blog
Step 2:
<project default="RunTests_xUnit">
<target name="RunTests_xUnit" description="Runs the discovered xUnit.net unit tests" depends="someCompileStep">
<!-- Outer loop to search through a list of different locations -->
<!-- Folders to be searched should listed as a semicolon deliminated list in the 'in' attribute -->
<foreach item="String" in="${TestAssemblyOutputPath}" delim=" ;" property="testsPath">
<echo message="Searching for xUnit.net test suites in ${testsPath}" />
<!-- Inner loop to search for dlls containing unit tests -->
<foreach item="File" property="filename">
<in>
<items basedir="${testsPath}">
<!-- see http://nant.sourceforge.net/release/0.91/help/types/fileset.html for how to include or exclude specific files or file patterns -->
<!-- attempt to run tests in any dlls whose name ends with UnitTestSuite.dll' -->
<include name="**UnitTestSuite.dll" />
</items>
</in>
<do>
<property name="testDLLName" value="${path::get-file-name-without-extension(filename)}" />
<echo message="Testing ${testDLLName} with xUnit.net" />
<exec program="${xunit-console.exe}" failonerror="true" resultproperty="resultVal">
<arg line="${testsPath}\${testDLLName}.dll /xml ${xUnitTestLogsFolder}${testDLLName}-xUnitResults.xml" />
</exec>
<fail message="Failures reported in ${testDLLName}." failonerror="true" unless="${int::parse(resultVal)==0}" />
</do>
</foreach>
</foreach>
</target>
</project>
Step 3:
<publishers>
<merge>
<files>
<file>C:\logs-location\xUnitTestLogs\*UnitTestSuite-xUnitResults.xml</file>
<file>C:\logs-location\TestLogs\*Tests-Results.xml</file>
</files>
</merge>
<xmllogger />
<statistics />
</publishers>
Step 5:
<buildPlugins>
<buildReportBuildPlugin>
<xslFileNames>
...
<xslFile>xsl\xUnitSummary.xsl</xslFile>
</xslFileNames>
</buildReportBuildPlugin>
...
<xslReportBuildPlugin description="xUnit.net Report" actionName="xUnitReport" xslFileName="xsl\xUnitSummary.xsl" />
...
</buildPlugins>

Deploying Custom theme in production server

I'm working on a Liferay project.
I'm developing a new Liferay theme using Plugins SDK.
I wonder is it better to use ANT or MAVEN for the project?
Because I managed to run both projects in eclipse.
Also is there any way to deploy automatically the theme in the production server ? (Distant server using tomcat).
For now I'm just using auto deployment, copying the war file to the /deploy file.
Regards
You can add remote server to your Eclipse with Plugins SDK, check https://www.liferay.com/documentation/liferay-portal/6.2/development/-/ai/developing-apps-with-liferay-ide-liferay-portal-6-2-dev-guide-02-en
(this may be helpful for older versions of plugins-sdk)
Assuming that you have ssh access to the remote server, the following ant target can be added and used in /liferay-plugins-sdk/build-common-plugin.xml
<property name="web-server" value="11.11.11.11" />
<property name="web-server-username" value="yourusername" />
<property name="web-server-password" value="yourpassword" />
<property name="web-server-deploy-folder-path" value="/liferay-x.x/deploy" />
<target name="remote-deploy" depends="war">
<echo message="Copying plugin to remote server ..." />
<scp
file="${plugin.file}"
todir="${web-server-username}:${web-server-password}#${web-server}:${web-server-deploy-folder-path}"
trust="true"
/>
<echo message="Done!" />
</target>

Create file that keeps time and revision number of my project when I compile

Currently the file is only keeping the latest revision. I want to use a different file where the history is kept. Each time ANT is used, I want it to append the time and revision number on that file. On the home screen I will just have a link to that file.
This is how its written now:
<target name="compile-java" depends="prepare,compile">
<exec dir="${project.dir}" executable="tools/version.sh" output="${src.web.dir}/date_compile.jsp">
<arg line="" />
</exec>
<propertyfile file="${src.web.dir}/date_compile.jsp">
</propertyfile>
</target>
I want to append new revision while keeping old revision data too.
This is just a matter of using the BuildNumber or PropertyFile task to create the build version number file and then read the file to get that number, create also a timestamp of the build and then append them both to another file.
Here is a basic idea of how to do it. Starting from that you should be able to write something of the likes of this:
<project default="increment">
<target name="increment">
<tstamp>
<format property="build.time" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<propertyfile file="build.properties">
<entry key="build.number" type="int" operation="+" default="0" />
</propertyfile>
<property file="build.properties" />
<echo message="Build ${build.number} on ${build.time}
" append="true" file="build.history" />
</target>
</project>
This creates two files: build.properties with your build number (always the last number as it is overwritten on each build) and build.history that contains a list of build numbers and a timestamp of each build.
EDIT : Based on the comments, if the version.sh outputs the revision and date to date_compile.jsp and overrides it on each build then - to keep history - you just need to load date_compile.jsp in your build and append its content to another file, something like this:
<target name="compile-java" depends="prepare,compile">
<exec dir="${project.dir}" executable="tools/version.sh" output="${src.web.dir}/date_compile.jsp">
<arg line="" />
</exec>
<loadfile property="revision" srcfile="${src.web.dir}/date_compile.jsp" />
<echo message="${revision}<br>
" append="true" file="${src.web.dir}/compile_history.jsp" />
</target>
Not 100% sure what you want, but it looks like a combination of <tstamp/>, <echo>, and <propertyfile/>.
You can use <propertyfile> to specify the property file where the build number is stored, and for editing it:
<propertyfile file="${build.prop.file}">
<entry key="build.number"
value="1"
default="0"
operation="+"/>
</propertyfile>
Now, you can include that property file in your build:
<property file="${build.prop.file}"/>
Which will set ${build.number}.
Next, you're going to get the date and time:
<tstamp>
<format property="build.time.stamp"
pattern="yyyy-mmm-dd.hh:mm:ss-zzzzz"/>
</tstamp>
Now, you'll append this to your log file
<echo append="true" file="${build.log}"
message="Building build # ${build.number} on ${build.time.stamp}"/>

how to catch a return value from a ssh task ant

I have defined a macro in ANT that checks if a dir exists on a remote linux box:
<macrodef name="checkIfDirExists">
<attribute name="host" />
<attribute name="username" />
<attribute name="password" />
<attribute name="dir" />
<sequential>
<runcommand executable="[ -d #{dir} ]" host="#{host}" username="#{username}" password="#{password}"/>
</sequential>
</macrodef>
runcommand is just a wrapper macro for sshexec task that validates some additional stuff, but basically it's just an sshexec.
Right now, if i run this, it works in a way that if the directory exists the build go on but if it doesn't exist the build fails since [ -d #{dir} ] return value is 1.
I want to be able to check the return value so i can put it in a conditional tag, for example if the dir exists, skip, and if it doesn't create it with mkdir.
Is this possible ?
This is a total stab in the dark, I don't know if ant will let you do this. However if it's invoking bash on the remote host, it should work.
<macrodef name="checkIfDirExists">
<attribute name="host" />
<attribute name="username" />
<attribute name="password" />
<attribute name="dir" />
<sequential>
<runcommand executable="[ -d #{dir} ] || mkdir #{dir}" host="#{host}" username="#{username}" password="#{password}"/>
</sequential>
</macrodef>
This way if the directory exists it will short circuit and return success. If it doesn't exist, it will call mkdir. If mkdir fails, then ant will fail.
To get the exit code of the command, use a combination of resultproperty and failonerror:
<sshexec command="[ -d #{dir} ]" ... failonerror="false" resultproperty="exitCode"/>
The exit code will be in the property named exitCode after this.
See Ant sshexec docs. Works for Ant 1.9.4 and higher.

Resources