-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
more usage info for newbies? #21
Comments
#!/usr/bin/env dub
/+ dub.sdl:
name "example"
dependency "d-unit" version=">=0.8.0"
+/
import dunit;
import std.string: toLower;
string strToLower(string s){
string ret;
foreach(c; s) ret ~= toLower(c);
return ret;
}
class StringTest
{
mixin UnitTest;
@Test
void testStrToLower()
{
assertEquals("lower", strToLower("LoWer"));
}
@Test
void testStrToLowerWithUnicode()
{
assertEquals(" lower2 ü", strToLower(" LoWer2 Å"));
}
}
mixin Main;
By the way: it may be a good idea to separate the application (your However, consider reading https://dlang.org/blog/2017/10/20/unit-testing-in-action/ for alternatives to dunit. |
Ah yes, those are very good pointers. The simple
I see there are two big disadvantages when merging code and test code in one file:
Anyway for small programs, or when exploring something not very well-known, it is very convenient to put code and test code in one file. Mentioning this, I miss IDE support for creating tests in Python and Java. It will be very nice if with shortcut keys we can create test cases for current function or class' method in a separate test file. And jump back and forth between code and test code :) |
The DLang plugin for IntelliJ has support for DUnit, although it is quite limited at the moment. (You can only specify 1 test module for a test run configuration).
|
Move shared to the right hand side of the function
I ran the example.d, the output style of tests are something I would like to use for my code. However, reading example.d content, it is not clear to me what is the real code and what is the test code. And more practically, how do I migrate from the code using D built-in unittest to
dunit
.For example, consider myDbuiltinTest.d:
My questions:
dunit
in this case?.d
files and execute them individually?The text was updated successfully, but these errors were encountered: