High Folks,
I started to learn Kotlin and I ran into a dependency issue for "kotlin.test" on my Linux machine which I don't know to overcome:
kotlinc first_unit_test.kt -> fails
On the Kotlin webpage it is mentioned that "kotlin.test" is
under the hood, but I don't know how include and activate
it on the command line.
first_unit_test.kt:1:15: error: unresolved reference: test
import kotlin.test.Test
^
first_unit_test.kt:2:15: error: unresolved reference: test
import kotlin.test.assertTrue
^
first_unit_test.kt:6:3: error: unresolved reference: Test
#Test
^
first_unit_test.kt:9:3: error: unresolved reference: assertTrue
assertTrue("Hello" in "Hello World!")
^
Even if I include the runtime I get the same error :-(
kotlinc first_unit_test.kt -include-runtime -d first_unit.jar
Here the very small test program:
import kotlin.test.Test
import kotlin.test.assertTrue
class first_unit_test {
#Test
fun testHello()
{
assertTrue("Hello" in "Hello World!")
}
}
I also tried the "-cp" switch, but I couldn't get it to work.
Actually I want to compile and later I want to run those unit test,
and I have no clue how to make them run either ...
Okay I made some progress:
first I copied
kotlin-test.jar
kotlin-test-junit.jar
into the build folder and
I changed the build command:
kotlinc -cp ".:./kotlin-test.jar:./kotlin-test-junit.jar" first_unit_test.kt -include-runtime -d first_unit.jar
Now I have a new error for which I do not have a clue:
first_unit_test.kt:6:3: error: this class does not have a constructor
#Test
^
Why do I have to provide a constructor?
import kotlin.test.Test
import kotlin.test.assertTrue
class first_unit_test {
#Test
fun testHello()
{
assertTrue("Hello" in "Hello World!")
}
}
Related
Gradle 7.3
Kotlin 1.7.10
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
internal class MainTest {
#Test
fun `Test how work Kotlin in Junit 5`() {
Assertions.assertThat("nice").isEqualTo("nice")
}
}
I try to run this test like this:
gradle test --tests com.myproject.MainTest.`Test how work Kotlin in Junit 5`
But get error:
Command 'Test' not found, did you mean:
command 'test' from deb coreutils (8.30-3ubuntu2)
Try: sudo apt install <deb name>
> Task :app:test FAILED
I have a following pyunit test case code where I am collecting the result of the function (True or False) and using it to drive my assertion. However, I am getting the "no attribute" error for assertTrue. What is missing here?
I am using python 2.7.8 and pyunit version of PyUnit-1.4.1-py2.7.
The same code when run from the Eclipse (pydev plugin) from my Mac, it works fine. Only when I take this to my Linux box, it does throw below error. So to me it looks like some package incompatibility problem.
import json
import unittest
class TestSwitch(unittest.TestCase):
def testFunction(self):
self.assertTrue(True, "test case failed")
Below is the test suite class.
import unittest
from mysample import TestSwitch
# Create an instance of each test case.
testCase = TestSwitch('testFunction')
# Add test cases to the test suite.
testSuite = unittest.TestSuite()
testSuite.addTest(testCase)
# Execute the test suite.
testRunner = unittest.TextTestRunner(verbosity=2)
testRunner.run(testSuite)
It throws below error.
bash-3.2$ python mysuite.py
testFunction (mysample.TestSwitch) ... ERROR
======================================================================
ERROR: testFunction (mysample.TestSwitch)
----------------------------------------------------------------------
Traceback (most recent call last):
File "workspace/pyunit/mysample.py", line 7, in testFunction
self.assertTrue(True, "test case failed")
AttributeError: TestSwitch instance has no attribute 'assertTrue'
----------------------------------------------------------------------
Ran 1 tests in 0.000s
FAILED (errors=1)
bash-3.2$
For now I've figured a workaround for this problem by using 'assertEqual' comparing with a boolean value and it works. I am not sure why 'assertTrue' and for that matter 'assertFalse' is having problem. I did not change any package version or anything.
The workaround code is as below.
17 def testFunction(self):
18 res = True
19 self.assertEqual(res, True, 'test case failed')
I am using PTVS 2.1 in VS 2010 with Iron Python 2.7.5. I am executing Test.py file which has the following code :
import sys
def main(argv = sys.argv):
argv1=argv[0:]
for arg in argv1:
print arg
and my C# code to call this script is:
var py = Python.CreateEngine();
var argv = new List<string>();
argv.Add("Item1");
argv.Add("Item2");
argv.Add("Item3");
dynamic obj = py.ExecuteFile("Test.py");
obj.main(argv);
But when I try to call the Python script from the C# script, it throws an error: expected int - got slice, whereas when I call the same Python script from a Python project, it runs successfully. Why it is so?
I am trying to replicate a namespace kind of pattern in D. I would like to have one class per file and be able to use a single import statement to include all classes from a group of files.
in my root folder I have moduleExp.d
import foo.module;
import std.stdio;
void main()
{
writeln("hello world");
auto quakk = new Quakk();
quakk.write();
}
In my foo folder I have module1.d:
module foo.module1;
import std.stdio;
class Quakk
{
public string name = "thename";
public void write()
{
writeln(this.name);
}
}
Also in foo folder, I have module.d which I thought I could use to publicly import all my class modules into so they can be used in moduleExp.d of the root folder.
module foo.module;
public import foo.module1;
When I try to compile on Windows from the root folder with rdmd moduleExp, I get errors:
moduleExp.d(1): Error: identifier expected following package
moduleExp.d(1): Error: ';' expected
Failed: ["dmd", "-v", "-o-", "moduleExp.d", "-I."]
I'm not sure what I'm doing wrong here. if I change line 1 in module.Exp.d to import foo.module1; then everything works.
module is a reserved keyword that you shouldn't use as a module name. And what you are trying to do exists as a feature in dlang called package modules. Look in http://dlang.org/module.html for documentation.
So basically, you have a module under the folder foo, its name should be package.d, where you publicly import the modules within foo and any other modules that you want. Example:
module foo; // notice the module name is used
// for the package module and not foo.package
public import foo.module1;
public import foo.module2;
...
And now when you want to import the package, just write import foo.
Given the following code file (named server.go) in Go:
package glimpse
func SplitHeader() string {
return "hi there"
}
and the accompanying test file (server_test.go):
package glimpse
import (
"testing"
)
func TestSplitHeader(t *testing.T) {
answer := SplitHeader()
if answer == "" {
t.Error("No return value")
}
}
Why is it the following command:
go test server_test.go
returns
# command-line-arguments
./server_test.go:9: undefined: SplitHeader
I'm certainly missing something catastrophically obvious.
Use only
$ go test
from within the package directory to perform testing. If you name specific files as an argument to go test, then only those file will be considered for the build of the test binary. That explains the 'undefined' error.
As an alternative, use "import path" as an argument to go test instead, for example
$ go test foo.com/glimpse